Single thread and high performance of Redis

Is Redis single-threaded?

The single thread of Redis mainly means that Redis's network IO and key-value pair reading and writing are completed by one thread. This is also the main process of Redis providing key-value storage services to the outside world. But other functions of Redis, such as persistence, asynchronous deletion, cluster data synchronization, etc., are actually executed by additional threads.

Why is Redis single-threaded so fast?

Because all its data is in memory, all operations are memory-level operations, and a single thread avoids the performance loss of multi-thread switching. Because Redis is single-threaded, you must be careful when using Redis instructions. For those time-consuming instructions (such as keys), you must use them with caution. If you are not careful, Redis may freeze.

How does Redis single thread handle so many concurrent client connections?

Redis's IO multiplexing: Redis uses epoll to implement IO multiplexing, putting connection information and events into the queue, and then into the file event dispatcher. The event dispatcher distributes the events to the event processor.
Insert image description here

Check the maximum number of connections supported by redis, which can be modified in the redis.conf file, # maxclients 10000

127.0.0.1:6379> CONFIG GET maxclients
    ##1) "maxclients"
    ##2) "10000"

Guess you like

Origin blog.csdn.net/qq_43802454/article/details/121181759