#Redis is single-threaded, saving a lot of time for context switching threads.
Why is redis single-threaded?
1. Official website explanation
Since Redis is a memory-based operation, the CPU is not the bottleneck of Redis. The bottleneck of Redis is most likely the size of machine memory or network bandwidth. Since single-threading is easy to implement and the CPU does not become a bottleneck, it is logical to adopt a single-threaded solution.
(Video tutorial recommendation: java video)
2. Performance indicators
Ordinary notebooks can easily process per second Hundreds of thousands of requests.
3. Detailed reasons
1. No performance consumption of various locks is required
Not all Redis data structures are simple key values ( Key-Value), but have complex structures such as lists and hashes. These structures can perform fine-grained operations, such as appending elements to the end of a long list and adding them to a hash or deleting objects.
These operations may require a very large number of locks, resulting in a significant increase in synchronization overhead. In short, in the case of a single thread, there is no need to consider various locks, no lock release operations, and no performance consumption due to possible deadlocks.
2. Single-threaded multi-process cluster solution
The function of single-thread is actually very powerful, and the efficiency of each core is also very high. Multithreading can naturally have higher performance limits than single threading. However, in today's computing environment, even single-machine multi-threading constraints often cannot be met. What needs further exploration are multi-server clustering scenarios, and multi-threading technology in these scenarios is still not available.
So a single-threaded, multi-process cluster is a good solution.
Recommended tutorial: java entry program
The above is the detailed content of Why is redis single-threaded?. For more information, please follow other related articles on the PHP Chinese website!