Redis nodes configuration and memory usage

42 views
Skip to first unread message

preetika tyagi

unread,
Sep 18, 2018, 4:01:14 PM9/18/18
to Redis DB
Hi,
I am new to Redis and I am trying to understand the Redis architecture/internals. I understand we can have multiple instances/nodes of Redis (e.g. master and slave instances) on one physical machine.
However, how do I configure memory usage for each instance? 
Also, when snapshot takes place, the memory usage goes up due to rdb file in the memory until it is either written to the disk or transferred to a slave. Also, the child process used either for snapshot or AOF consumes memory.
In addition, if we configure Sentinel to run on all physical machines, that takes up some memory too.

So basically, what should be the strategy to assign memory usage for each instance?
Also, can we have more than 2 Redis nodes on a physical machine (e.g. master 1, slave 2, slave 3)?

Thank you for your help!


hva...@gmail.com

unread,
Sep 21, 2018, 12:46:44 PM9/21/18
to Redis DB
Redis is not very different from other data storage/query software.

If you have a group of RDBMS instances in a master+slave relationship, for example MySQL, Postgres, or Oracle, would you put the master instance and one or more slave instances on the same physical machine?  There are benefits in doing this and there are drawbacks.  With Redis there are pretty much the same benefits and the same drawbacks.

Like with the RDBMS instances, your Redis slave processes will hold the same data as the master process, and, as a result, will consume about the same amount of memory.  Calculating the memory size for each instance amounts to dividing the available memory by the number of Redis instances you want to run on the machine.  However, you should not consume all available memory with the Redis processes.  Reason number 1 is:  You need room to grow the amount of data you hold in Redis.  Reason number 2 is:  The operating system needs 20-30% of the total memory to be left unused by processes like Redis, so that free memory can be used to buffer disk writes, and short-lived processes like cron jobs.

Since the Redis master and slaves hold the same data, you don't need them all to save snapshots to disk.  Just one Redis process saving snapshots will be sufficient for most situations, especially when you have the master and slaves on the same physical machine, where a slave's snapshot file is available to use for recovering the master.  If the disk writes or memory usage are a problem, it's possible to run a slave on another physical server, and make that slave write the snapshots.

The act of saving snapshots does not by itself increase the memory consumed by a Redis server process.  The operating system will use free memory as write buffers, but this does not increase the consumption of any running processes.  People can see the memory consumption of a Redis server process grow while it is writing snapshot data to disk, but this occurs in a busy server with slow disk.  I'm happy to describe the details of how and why that occurs, but I won't in this reply because it's already pretty long.  However, if you move the snapshot activity to a different machine with plenty of ram and fast disks, the memory growth won't affect the Redis processes that are serving your data to clients.

You can have multiple Redis processes on the same physical (or virtual) machine.  You simply need enough resources on the machine to support them.  In order of importance: Memory, Cpu, Network i/o, and Disk space.
  • Memory:  has been covered already, but it mostly depends on the size of the data you will put into Redis.
  • Cpu:  a Redis server process is mostly single-threaded, so you want 1-2 cpu cores per Redis process.
  • Network i/o:  depends mostly on the read/write activity with client processes,
  • Disk:  Redis does not use a lot of disk space or consume a lot of disk i/o except for the snapshot files.  If you dedicate a separate machine for snapshots, then your main machine(s) with the Redis master and slave processes won't need a lot of disk and won't need it to be as fast.

Running multiple Redis processes means each must have a different configuration file, which tells it to listen on a different TCP port, use a different directory on disk as its working area (the 'dir' parameter in the config file), and a different pid (process id) file.

Yes, Sentinel processes will use some resources of their own.  If you run all your Sentinel processes on the same machine (and it's running all the Redis server processes), how will the Sentinels be able to detect when client machines cannot reach the Redis machine?  It's easy to do when the Sentinel is on a different machine (perhaps even on the machines where the clients are), but hard to do on the Redis machine.  It's your network and servers, so it's your decision where to run Sentinel, but consider what problems you need Sentinel to detect and act upon, and which machines it can serve you the best on.

preetika tyagi

unread,
Sep 26, 2018, 1:36:43 PM9/26/18
to redi...@googlegroups.com
@hvarzan  
Thank you for the detailed response. It also clarified other questions I had in mind.


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages