rddis high concurrency processing

Reference: https://www.cnblogs.com/wanlei/p/10464517.html

About Redis high concurrency processing

Redis high concurrency and fast reasons

1.Redis is memory-based, very fast read and write speeds of memory;

2.Redis is single-threaded, eliminating a lot of thread context switching time;

3.Redis using multiplexing techniques, can handle concurrent connections. Internal achieve non-blocking IO using epoll, epoll + uses a simple event framework for their own implementation. Epoll in reading, writing, close, connections are transformed into an event, and then use epoll multiplexing characteristics, and never wasted little time on the io.

The reason focuses on the following single-threaded design and fast IO multiplexing core design

Why Redis is single-threaded

1. The official answer

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.

2. Performance Indicators

Redis performance on the official website also has ordinary notebook easily handles hundreds of thousands of requests per second.

3. The detailed reasons

1) does not need to lock the various performance overhead

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.

So single-threaded, multi-process clusters would be a stylish solution.

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.

IO multiplexing

Redis IO network using multiplexing techniques to ensure that when multiple connections, high throughput systems.

Multiple - refers to a plurality of socket connections, multiplexing - refers to a multiplex thread. There are three main multiplexing technology: select, poll, epoll. epoll is the latest multiplexing technology is currently the best.

Here "multiplexing" refers to multiple network connections, "multiplexing" refers to reuse the same thread. Multi-channel I / O multiplexing technique that allows efficient processing a plurality of single thread connection request (IO minimize the time consumed by the network), and the data in memory Redis operation is very fast (within a memory operation will not be here performance bottleneck), the above two main Redis created with high throughput.

Redis high concurrency quick summary

  1. Redis is pure in-memory database, are generally simple access operation, the thread take up a lot of time, time spent focused on IO, so fast read speed.

  2. To tell you the context of IO, Redis using a non-blocking IO, IO multiplexing, using a single thread to poll the descriptor, will open the database, close, read, write, are converted into the event, reducing the thread switching time switching and competition.

  3. Redis using a single-threaded model to ensure that each of the atomic operation also reduces context switching and competition thread.

  4. Further, the data structure also helped a lot, using the Redis entire hash structure, high reading speed, there are some special data structure, stored data is optimized, such as the compression tables, storing data compression short, another example , jump table, using an ordered data structure to speed read.

  5. Another point, Redis event-splitter own implementation of more efficient internal use of non-blocking execution mode, the handling capacity is relatively large.

Guess you like

Origin www.cnblogs.com/zanao/p/11877331.html