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--
How to solve redis cache avalanche and cache penetration? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Cache penetration
Cache traversal refers to querying a data that must not exist. Because the cache misses, and for the sake of fault tolerance, if the data cannot be found from the database, the cache will not be written, which will cause the non-existent data to query to the database every time, which loses the meaning of the cache. That is, the requested data misses in the cache, causing the request to go to the database.
Solution
Bloom filtration
All possible query parameters are stored in the form of hash, checked at the control layer first, and discarded if they do not match, thus avoiding the query pressure on the underlying storage system.
Cache empty object
When the storage layer misses, even the returned empty object will be cached, and an expiration time will be set, and then accessing this data will be fetched from the cache, protecting the back-end data source.
But there are two problems with this approach:
If null values can be cached, this means that the cache needs more space to store more keys, because there may be a lot of null keys
Even if the expiration time is set for null values, there will still be a period of time window inconsistency between the data in the cache layer and the storage layer, which will have an impact on businesses that need to maintain consistency.
Cache avalanche
We all know that it is impossible for Redis to cache all the data (memory is expensive and limited), so Redis needs to set an expiration time for the data and delete expired key-value pairs. It uses two strategies of lazy deletion + periodic deletion to delete expired keys.
If the expiration time of the cached data setting is the same, and Redis happens to delete all of the data. This will cause these caches to expire at the same time, and all requests will be made to the database.
Redis hung up, request all to go to the database.
Set the same expiration time for the cached data, causing the cache to expire within a certain period of time, and all requests go to the database.
Solution
Ensure high availability of cache layer services
Even if individual nodes, machines, or even computer rooms are down, services can still be provided. For example, Redis Sentinel and Redis Cluster have achieved high availability.
Rely on isolation components to limit current and downgrade the backend
After the cache expires, the number of threads reading the database write cache is controlled by locking or queuing. For example, only one thread is allowed to query data and write cache for a key, while other threads wait.
Data preheating
You can update the cache in advance through the cache reload mechanism, and then manually trigger the loading of different cache key before large concurrent access occurs, and set different expiration time to make the time point of cache expiration as uniform as possible.
After reading the above, have you mastered the solutions to redis cache avalanche and cache penetration? If you want to learn more skills or 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.