redis Why is single-threaded?

A, Redis Why is single-threaded?

Because Redis memory operation is based on the bottleneck, CPU Redis not the, most likely Redis bottleneck machine memory size or bandwidth. Since the single-threaded easy to implement, and the CPU does not become a bottleneck, it is logical to adopt a single-threaded program.

Second, the detailed reasons:

1, the lock does not require the various properties consumption

Redis data structure is not entirely simple Key-Value, there List, hash and other complex structures which are likely to undergo a very fine-grained operation such as adding an element in a long list later, add hash which or delete

An object. These operations may need to add a lot of locks, resulting in synchronization overhead is greatly increased.

In short, in the single-threaded case, we will not have to consider various issues lock, lock lock release operation does not exist, not because of a deadlock may occur and cause performance overhead.

2, single-threaded multi-process cluster scheme

Single-threaded power actually very powerful, very high efficiency per core, multi-threaded nature can have higher performance than single-threaded cap, but in today's computing environment, even a single multi-threaded cap also often can not meet the need, the need for further exploration of multi-server clustered programs that are multithreaded technology is still unobtainable.

3, CPU consumption

Single-threaded, to avoid unnecessary context switches and competitive conditions, there is no multi-process or multi-threaded switching lead is consumed CPU.

However, if the CPU becomes the bottleneck Redis, or do not want to let other server CUP nuclear idle, how to do?

Can be considered more than a few Redis process, Redis is a key-value database, there is no constraint between is not a relational database, data. As long as the client distinguish which key on which Redis process it.

Three, Redis advantages and disadvantages of single-threaded

1, single-process single-threaded advantage

Code clearer, simpler processing logic

You do not have to consider various issues lock, lock lock release operation does not exist, not because of possible deadlocks caused by consumption of performance

Multi-process or multi-threaded switching due to the absence of consumption of CPU

2, single-process single-threaded malpractice

You can not play a multi-core CPU performance, but can open multiple instances of Redis single to perfect;

Guess you like

Origin www.cnblogs.com/jxxblogs/p/12238044.html