Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ensure multiple redis instances running on different cores?

Tags:

redis

I've a 4-core server and I want to run redis on it. To fully utilize the capabilities of the 4 cores, it is expected to launch 4 redis instances, since redis is designed to be single-threaded.

However, I'm curious how to ensure that the 4 instances are exactly running on 4 different cores? How can an instance decide the core on which it is running when it is launched?

like image 216
ciphor Avatar asked Aug 15 '12 09:08

ciphor


People also ask

Can Redis use multiple cores?

Redis is, mostly, a single-threaded server from the POV of commands execution (actually modern versions of Redis use threads for different things). It is not designed to benefit from multiple CPU cores.

How do I run multiple instances of Redis?

Open command line as administrator. Change directory to C:\Program Files\Redis. Run the below command line to create a new service instance. Customize the service name, display name, and conf file path to match your configuration (in bold below), where XXXX is the port number for the new instance.


1 Answers

Redis itself does not provide such guarantee.

If you launch 4 instances, there will be 4 different processes that the operating system will have to get scheduled on the 4 cores. It is up to the OS to perform this load balancing, optimizing the performance of the system.

Now, if you really want to bind each instance to a specific core, modern OS usually provides tools to enforce the execution of a process on a specific CPU core.

For instance, on Linux, you can have a look at the taskset and the numactl commands.

In practice, you need to be careful with this, because once you launch Redis on a specific core (setting a CPU mask), all the threads and child processes will inherit from this CPU mask. So when Redis will try to trigger a background save operation, or a background AOF rewrite, it will seriously impact the performance of the Redis instance. This is due to the fact the main Redis thread will have share the CPU core with the background operation (which is typically CPU consuming).

If you really want to play with CPU binding (but is it really a good idea?), you need to bind N Redis instances to N+1 CPU cores, keeping one core free for the background operations, and make sure at most one background operation can run at the same time for these instances.

like image 78
Didier Spezia Avatar answered Sep 28 '22 00:09

Didier Spezia