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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the redis expiration strategy". In the daily operation, I believe many people have doubts about the redis expiration strategy. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the redis expiration strategy?" Next, please follow the editor to study!
All Redis data structures can be set to expire, and when the time is up, it will be deleted automatically. You can imagine that there is a god of death inside the Redis, keeping an eye on all the key with an expiration time, and harvest as soon as the lifespan arrives.
You can further consider from the perspective of death whether too many key expires at the same time that you are too busy to do so. At the same time, because Redis is single-threaded, the harvest time will also take up the processing time of the thread, if the harvest is too busy, will it cause stutters in the online read and write instructions?
Expired key collection
Redis will put each key with an expiration time set into a separate dictionary, which will be traversed regularly later to delete the expired key. In addition to scheduled traversal, it also uses a lazy policy to delete an expired key, which means that when the client accesses the key, the redis checks the expiration time of the key and deletes it immediately if it expires. Scheduled deletion is centralized processing, while inert deletion is piecemeal processing.
Timing scanning strategy
By default, Redis performs ten expiration scans per second, which does not traverse all the key in the expired dictionary, but uses a simple greedy strategy.
Random 20 key from expired dictionaries
Delete the expired key in these 20 key
If the out-of-date key ratio exceeds 1amp 4, repeat step 1
At the same time, in order to ensure that the expired scan will not cycle too much, resulting in thread jam, the algorithm also increases the upper limit of scanning time, which will not exceed 25ms by default.
Imagine that all the key in a large Redis instance expires at the same time. What would happen?
There is no doubt that Redis continues to scan expired dictionaries (multiple loops) until expired key in expired dictionaries becomes sparse (the number of loops decreases significantly). This will lead to obvious stutters in online read and write requests. Another reason for this stutter is that the memory manager needs to recycle memory pages frequently, which also results in some CPU consumption.
When the client request arrives, if the server happens to enter the expired scan state, the client request will wait for at least 25ms before it will be processed. If the client sets the timeout period for a short time,
For example, 10ms, there will be a large number of links closed due to timeouts, and a lot of exceptions will occur on the business side. And you can't see the slow query record in Redis's slowlog at this time, because slow query refers to slow logical processing and does not include waiting time.
At this point, the study of "what are the redis expiration strategies" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.