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 the concept of Redis cache penetration and cache avalanche, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe that after reading this article, the concept of Redis cache penetration and cache avalanche will be harvested. Let's take a look at it together.
I. Cache penetration
1. Concept
The concept of cache penetration is very simple, the user wants to query a data, found that redis memory database does not, that is, cache does not hit, so query the persistence layer database. There is no such thing, so the search failed. When there are a lot of users, the cache misses, so they all request the persistence layer database. This puts a lot of stress on the persistence tier database, which is equivalent to cache penetration.
Here, we need to pay attention to the difference between cache breakdown and cache breakdown. Cache breakdown refers to a key that is very hot. It constantly carries large concurrency. Large concurrency focuses on accessing this point. When this key fails at the moment, continuous large concurrency will break through the cache and directly request the database, just like cutting a hole in a barrier.
There are many solutions to avoid cache penetration. A few are described below.
2. Solution
(1) Bloom filter
Bloom filter is a data structure, spam sites and normal sites add up to billions of statistics worldwide. Network police to filter these spam sites, the total can not go to the database one by one to compare it, this can use Bloom filter. Suppose we store 100 million spam addresses.
One hundred million binary bits can be used, and then the police use eight different random number generators (F1,F2,...,F8) to generate eight information fingerprints (f1, f2,..., f8). A random number generator G is then used to map the eight information fingerprints to eight natural numbers g1, g2, …,g8 from 100 million to 100 million. Finally, set all eight binary positions to one. The process is as follows:
One day, the network police found a suspicious website and wanted to determine whether it was XX website. First, the suspicious website was mapped to 8 points on the 100 million bit array by hash. If one of the eight points is not 1, it can be judged that the element must not exist in the set.
So how does this bloom filter solve cache penetration in redis? It is very simple to store all possible query parameters in hash form first. When the user wants to query, use Bloom filter to find that they are not in the collection, and discard them directly. No longer query the persistence layer.
The form is simple.
2. Cache empty objects
When the storage layer misses, even if the returned empty object is cached, an expiration time will be set, and then the data will be retrieved from the cache, protecting the backend data source.
But there are two problems with this approach:
If nulls can be cached, this means that the cache needs more space to store more keys, because there may be a lot of nulls.
Even if an expiration time is set for null, there will still be a time window inconsistency between cache and storage tier data, which will have an impact on businesses that need to maintain consistency.
II. Cache avalanche
1. Concept
Cache avalanche means that there is an error in the cache layer and it does not work properly. So all requests will reach the storage layer, and the number of calls to the storage layer will explode, causing the storage layer to hang up.
2. Solution
(1) redis high availability
The meaning of this idea is that since redis may hang up, I will add a few more redis, so that after one hangs up, the others can continue to work. In fact, it is a cluster built.
(2) Current limiting degradation
The idea behind this solution is to control the number of threads reading the database write cache by locking or queuing it after a cache failure. For example, only one thread is allowed to query data and write cache for a certain key, while other threads wait.
(3) Data preheating
Data warming means that before formal deployment, I first access the possible data in advance, so that some of the data that may be heavily accessed will be loaded into the cache. Manually trigger the loading of different cache keys before large concurrent accesses occur, and set different expiration times to make the cache invalidation time points as uniform as possible.
About "Redis cache penetration and cache avalanche concept is what" the content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "Redis cache penetration and cache avalanche." If you want to learn more knowledge, please pay attention to 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.