当前位置:网站首页>Redis - cache penetration, cache breakdown, cache avalanche
Redis - cache penetration, cache breakdown, cache avalanche
2022-07-01 00:05:00 【Salted fish_ Turn over】
List of articles
brief introduction
about Redis Cache , Use Redis The cache of , It improves application performance and efficiency , And caching plays a very important role in high concurrency scenarios , For data consistency ,Redis Caching is a very fatal problem , There are three such problems .
1、 Cache penetration
2、 Cache breakdown
3、 Cache avalanche
Then we will explain these three situations respectively , And give the solution :
Cache penetration
By default , When a user requests data , It's going to cache first (Redis) Search for , If not found, the cache misses , Then search in the database , A small number may not be a problem , But once a lot of data is requested ( For example, the second kill scene ) If the cache misses , It will all be transferred to the database , It puts a lot of pressure on the database , It may cause the database to crash . In network security, some people maliciously use this means to attack, which is called flood attack .
Solution :
1、 The bloon filter
For all possible query parameters, use Hash Form storage of , In order to quickly determine whether this value exists , In the control layer, the interception verification is performed first , If the verification fails, call back directly , Reduces the pressure on the storage system .
2、 Caching empty objects
If a request is not found in the cache or database , An empty object in the cache is used to process the subsequent request .
Be careful :
There is a flaw in doing so , Storing empty objects also requires space , A large number of empty objects will consume a certain amount of space , Storage efficiency is not high . The solution to this flaw is to set a shorter expiration time , Even if expiration time is set for null value , There will be some inconsistency between the data of cache layer and storage layer for a period of time , This has an impact on businesses that need to be consistent .
Cache breakdown
Compared to cache penetration , It's more purposeful , An existing key, At the moment the cache expires , There are a lot of requests at the same time , All of these requests go to DB, Cause instantaneous DB A lot of requests 、 The pressure surged . This is the cache breakdown , Just for one of them key The cache of is not available and causes a breakdown , But the others key You can still use cached responses , For example, in the hot search ranking , When a hot news is accessed by a large number of people at the same time, it may lead to cache breakdown .
Solution :
1、 Never expired data settings
In this way, the hot data will not be out of date , But when Redis When the memory space is full, some data will also be cleaned up , And it takes up space , Once there's more hot data , It's going to take up part of the space , So it's not recommended .
2、 Add mutex lock ( Distributed lock )
During a visit to key Before , use SETNX(set if not exists) To set up another short term key To lock in the present key The interview of , Delete the short term after the visit key. Ensure that only one thread can access at the same time . In this way, the requirements for locks are very high .
Cache avalanche
Cache avalanche means , At the same time , A large number of caches , Collective failure , It's like it hasn't been cached , At this time, it is assumed that there is such a second kill activity of double 11 and double 12 , Just at this moment, the cache is invalidated in batches , Then the cache fails , These requests are also directly pressed on the database , If the server is unlocked , This flow reaches a peak almost instantaneously , For a server , There will also be downtime .
Solution :
1、redis High availability
The meaning of this idea is , since redis It's possible to hang up , I'll add more redis, After this one goes down, others can continue to work , In fact, it's a cluster built .
2、 Current limiting the drop
The idea of this solution is , After cache failure , Control the number of threads that read the database write cache by locking or queuing . For example, to some key Only one thread is allowed to query data and write cache , Other threads wait .
3、 Data preheating
Data heating means before deployment , I'll go through the possible data first , In this way, some of the data that may be accessed in large amounts will be loaded into the cache . Manually trigger loading cache before large concurrent access occurs key, Set different expiration times , Make the cache failure time as uniform as possible .
边栏推荐
- Shell multitasking to download video at the same time
- Fastjson V2 simple user manual
- Is it safe to open a stock account of Huatai Securities online?
- When we look at the industrial Internet, we always look at it from the opposite of the consumer Internet
- In 2022, the latest JCR officially released the list of the latest global impact factors (top 600)
- Solution to the conflict between unique index and logical deletion
- How to close an open DNS resolver
- Maxpool2d explanation -- Application in arrays and images
- ABAQUS 2022 latest edition - perfect realistic simulation solution
- 需求评审,测试人员应该发挥怎样的价值?两分钟让你不再懵逼
猜你喜欢

6-1 exploit -ftp exploit

Vmware16 installing win11 virtual machine (the most complete step + stepping on the pit)

5g smart building solution 2021
![[UML] UML class diagram](/img/6f/30bd15967103969e600d69e618d8bf.png)
[UML] UML class diagram

BeanUtils. Copyproperties() vs. mapstruct

Random ball size, random motion collision

Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
![CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构](/img/ce/519778cd731f814ad111d1e37abd10.png)
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构

Software supply chain security risk pointing North for enterprise digitalization and it executives

Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
随机推荐
How to open a stock account? Is it safe to open a mobile account
Which is better, server rental or hosting services in the United States?
Fastjson V2 simple user manual
35家巨头科技公司联合组成元宇宙标准论坛组织
CTFSHOW框架复现篇
Random ball size, random motion collision
Shell multitasking to download video at the same time
How to use dataant to monitor Apache APIs IX
HP notebook disable touchpad after mouse is inserted
8253A寄存器浅析
Development of wireless U-shaped ultrasonic electric toothbrush
Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical
Lombok
基金客户服务
Is it safe to buy funds on the compass?
股票开户要如何办理呢?办理手机开户安全吗
[designmode] singleton pattern
五分钟搞懂探索式测试
lvm-snapshot:基于LVM快照的备份之准备工作
Ride: get picture Base64