In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the reasons why redis is single-threaded, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
First, why is Redis single-threaded?
Because Redis is a memory-based operation, CPU is not the bottleneck of Redis, and the bottleneck of Redis is most likely to be the size of machine memory or network bandwidth. Since single-threading is easy to implement and CPU will not be a bottleneck, it makes sense to adopt a single-threaded solution.
Second, the detailed reasons:
1. No performance consumption of various locks is required.
The data structures of Redis are not all simple Key-Value, but also complex structures such as list,hash. These structures may perform very fine-grained operations, such as adding an element after a long list and adding or deleting from the hash.
An object. These operations may require a lot 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 all kinds of locks, there is no lock release operation, and there is no performance consumption caused by possible deadlocks.
2. Single-thread multi-process cluster scheme
The power of single thread is actually very powerful, and the efficiency of each core is also very high, so multi-thread can naturally have a higher performance limit than single-thread, but in today's computing environment, even the upper limit of single-machine multi-thread can not meet the needs. What needs to be further explored is the scheme of multi-server clustering, and the technology of multi-thread in these schemes is still useless.
3. CPU consumption
The use of single thread avoids unnecessary context switching and competition conditions, and there is no CPU consumption caused by multi-process or multi-thread switching.
But what if CPU becomes a Redis bottleneck, or you don't want to leave the other CUP cores of the server idle?
You can consider several Redis processes. Redis is a key-value database, not a relational database, and there are no constraints between the data. As long as the client can tell which key is on which Redis process.
Third, the advantages and disadvantages of Redis single thread
1. The advantage of single process and single thread
The code is clearer and the processing logic is simpler.
There is no need to consider all kinds of locks, there is no lock release lock operation, and there is no performance consumption caused by possible deadlocks.
There is no CPU consumption due to switching caused by multi-process or multi-thread
2. Malpractice of single process and single thread
Multicore CPU performance cannot be achieved, but it can be improved by opening multiple Redis instances on a single machine.
These are all the reasons why redis is single-threaded. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.