Redis Single-Thread architecture
1 Single Thread model
Each invocation of the Redis client to the server goes through the sending command, executing the command, and returning the result in three processes. Where the command phase is executed, because Redis is single-threaded to handle the command, all commands that arrive at the service end are not executed immediately, all commands are entered into a queue and executed individually. and the order in which the commands sent by multiple clients are executed is indeterminate. But it is certain that no two commands will be executed at the same time, and that there will be no concurrency problem, which is Redis's single-threaded basic model. 2 Single-threaded model The reason for the million-level processing capacity per second
(1) Pure memory access. The data is stored in memory and the response time of memory is approximately 100 nanoseconds, which is an important basis for redis-trillion-level access per second.
(2) non-blocking I/o,redis using Epoll as I/O multiplexing technology, coupled with Redis's own event processing model will be epoll in the connection, read and write, shutdown are converted to time, not I/O waste too much time.
(3) single-threaded avoids the consumption of thread switching and race state generation.
(4) Redis using a single-threaded model, each command execution if takes a lot of time, can cause other threads to block, for Redis this high-performance service is fatal, so Redis is a high-speed execution-oriented database.