0

Let say I have 1GB RAM Ubuntu, I need to run both memcached and redis on the same machine

The usage of memcached is quite heavy (e.g. 1K read per second) and redis is less heavy (but still 10 read per second).

As my machine is powered by SSD, so I am thinking, let memcached run on real memory and let redis run on virtual memory, is it possible? (Since in my use case memory is only 1GB, I want to allocate more to memcached and less to redis, as I think on a SSD powered disk, 10 read per second is enough already).

Any idea to solve the issue?

Ryan
  • 5,831
  • 24
  • 72
  • 91
  • Have you tried just creating swap space and starting them up? What you're describing is pretty much the main purpose of the Linux memory management subsystem. You're overthinking this. –  Nov 12 '14 at 19:39

1 Answers1

0

You are not aware of this, but you are actually using virtual memory for all of those already. In essence, by default linux kernel will allow processes to map more memory than you have available on system. Most of that memory is not actively used so trick is to use virtual memory.

Linux kernel makes this nice trick and allows processes to map as much memory as they need, even more than system has.

For example, when process requests 1 GB of memory, kernel says ok here is your 1 GB of address space. Process does not use all this 1 GB, but say rather 100 MB, so kernel knowing that only 100 MB is used says; ok this 100 MB will be in RAM; but other 900 I will consider as possibly used in future and by doing so it allows other processes to request more memory regardless of you having physically only 1 GB.

At some point if processes checked out too much memory; kernel has heuristics to calculate pressure if memory reserves are getting low, it tries to free up some memory segments. Options in short are to drop some memory segments that are backed by filesystem (files loaded in memory), move some memory portions that were not used for a while to 'swap' (killing your disk IO)

In your example you can easily have memcache with 32 MB ram assigned, redis with 32 MB too, keep an eye on usage of memory in memcache per slabs. Redis will also be happy with 32 MB up to a point when it uses all 32 MB and it starts to check what was least used in it's memory to evict it (depending on usage of redis)

Memcache things to keep in mind.

Total memcache memory is split in X equally sized portions. Each portion is called slab and it accommodates key-value pairs of certain size range.

Some slabs may be full; some may be empty; depending on size of values stored in memcache. There is no way to statically define size of slab, and range of values it will be holding.

Once data is in memcache slab, it will get evicted either when - it's lifetime expires - slab is full and to fit a new key-value pair in slab, least used one needs to be pushed out

You need to check your memcache stats, if you're not doing many evictions you don't need to increase memory limit for memcache because it's doing great, and the hit count you mention is great too because those hits are served from memory; and not from some database which is slower data source.

Hrvoje Špoljar
  • 5,245
  • 26
  • 42