In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is a single thread in a redis service? Perhaps many people do not understand, in order to let you understand better, the editor summed up the following content, I hope you can gain something according to this article.
Redis communicates in socket mode, and the socket server can accept multiple client requests for connections at the same time, that is to say, the redis service faces multiple redis client connection requests at the same time, while the redis service itself runs in a single thread.
Suppose that now there are five clients of redis request simultaneously, An is the first to arrive a little bit first, and then the redis server starts to process the A request. It takes 30 seconds to establish the connection, 10 seconds to obtain the requested data, and 5 seconds to send the data back to the client, which makes a total of 45 seconds.
In other words, the next B request needs to wait 45 seconds. Note here that maybe these five requests are almost simultaneous. Because socket can process multiple requests at the same time, the time difference in the establishment of network connection phase is negligible. But in the second stage, the server needs to do nothing and wait for 10 seconds, which is intolerable for CPU and client.
So single-threading is very, very inefficient, but because of these similar problems, Redis single-threading essentially doesn't run this way. Let's discuss the true single-threaded operation of redis.
The establishment of a connection between the client and the server is handed over to socket, and multiple connections can be established at the same time (here it should be multi-threaded / multi-process). The established connection redis is known (why, look at socket programming and re-emphasize the importance of the foundation), and then redis will detect which connection has received the client's request data based on these established connections.
Note: it is not to detect which connection has been established, but to detect which has received the request data, and the detection action here is the beginning of a single thread. Once detected, the data processing phase begins based on the received data. Then return the data, and then continue to detect the next network connection that has received the request data.
Note that from detection to data processing to data return, the whole process is single-threaded.
This should be the so-called redis single thread. As for how complex the interior is, we don't care about it. What we pursue is to understand the process and be strict with the principle, but we can't eviscerate all the internal organs.
From the detection to the network connection that accepts the requested data to the final data return, the server only takes 5.1 seconds, which is the time after I magnified the data N times. The actual time is much less than this, which may be one ten thousandth of 5.1.
Why do you say that? because the data is processed in local memory, you can imagine how fast the final returned data is, although the final return data involves the network, but the network connection has been established, and this speed is also very fast. It's just a little slower than the data processing phase. So there is no need to worry about the efficiency of the single-threaded approach.
After reading the above, do you have any further understanding of single threading in redis services? If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.
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.