How to ensure that multiple instances of redis run on different kernels?

I have a 4-core server and I want to run redis on it. To take full advantage of the capabilities of 4 cores, it is expected that 4 instances of redis will be launched, since redis is designed for single-threading.

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

+8
redis
source share
1 answer

Redis does not provide such a guarantee.

If you run 4 instances, there will be 4 different processes that the operating system will have to schedule on 4 cores. It is OS dependent to perform this load balancing while optimizing system performance.

Now, if you really want to bind each instance to a specific core, a modern OS usually provides tools to ensure that the process runs on a specific processor core.

For example, on Linux, you can see taskset and numactl .

In practice, you need to be careful with this, because as soon as you run Redis on a specific kernel (specify a processor mask), all threads and child processes will inherit from this processor mask. Therefore, when Redis tries to start a background save operation or rewrite background AOF, this will seriously affect the performance of the Redis instance. This is because the main Redis thread will share the processor core with a background operation (which usually consumes the processor).

If you really want to play with CPU binding (but is this really a good idea?), You need to bind N Redis instances to N + 1 kernels, leaving one core free for background operations, and make sure that these instances can run one operation at a time.

+14
source share

All Articles