Joke Collection Website - Talk about mood - IO Reuse of Redis —— Understanding of Single Thread (Multithreading after Redis6.0)

IO Reuse of Redis —— Understanding of Single Thread (Multithreading after Redis6.0)

Reactor design pattern is an event-driven design pattern. The scheduler uses a demultiplexer to listen to multiple client requests. When a request event occurs, the scheduler assigns one or more client requests to different event handlers to improve the efficiency of event processing.

The following figure shows the reactor design pattern class diagram:

IO reuse based on reactor design pattern

The architecture diagram of IO multiplexing technology is as follows

note:

Multithreading may involve the consumption of locking and switching threads.

Time-consuming commands will lead to performance degradation, and the performance of CPU multi-core cannot be exerted.

Redis multithreading is only used to deal with the reading and writing of network data and protocol analysis, and the execution of commands is still single-threaded. This design change is to avoid introducing multithreading and making Redis complicated. Moreover, in the past, the use of single thread mainly considered that CPU was not the bottleneck of Redis, and there was no need for multi-thread concurrent execution, so the performance improvement brought by multi-thread mode could not offset the development and maintenance costs brought by it.

Now the introduction of multithreading model has solved the performance bottleneck of network IO operation. For the memory-based operation of Redis, it is still very fast, and sometimes the blocking of IO operation will affect the efficiency of subsequent operations. Instead, multi-thread concurrent IO operation is performed, and then the main thread performs memory operation, which can better alleviate the performance bottleneck caused by IO operation.

The architecture is as follows: