当前位置:网站首页>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 .
边栏推荐
- Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical
- Techo youth 2022 academic year college open class: behind the live broadcast of Lianmai, explore how to apply audio and video technology
- 基金客户和销售机构
- Don't worry about whether you can be a coder if you don't learn English well. Learn it first
- Simple application example of rhai script engine
- 基金客户服务
- ABAQUS 2022 software installation package and installation tutorial
- Thoughts on the future of data analysis in "miscellaneous talk"
- Code de conduite pour la vente de fonds et la gestion de l'information
- 需求评审,测试人员应该发挥怎样的价值?两分钟让你不再懵逼
猜你喜欢

The full technology stack, full scene and full role cloud native series training was launched to help enterprises build a hard core cloud native technology team

Gateway service gateway

How to edit special effects in VR panorama? How to display detailed functions?

Random ball size, random motion collision

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

206 page Shanghai BIM Technology Application and development report 2021
![CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构](/img/ce/519778cd731f814ad111d1e37abd10.png)
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构

BeanUtils. Copyproperties() vs. mapstruct

5g smart building solution 2021
![[leetcode] [SQL] notes](/img/8d/160a03b9176b8ccd8d52f59d4bb47f.png)
[leetcode] [SQL] notes
随机推荐
Random ball size, random motion collision
SSM integration process (integration configuration, function module development, interface test)
CTFSHOW框架复现篇
35家巨头科技公司联合组成元宇宙标准论坛组织
一次革命、两股力量、三大环节:《工业能效提升行动计划》背后的“减碳”路线图
Fund managers' corporate governance and risk management
MySQL index test
五分钟搞懂探索式测试
Flitter - sort list sort
When is it appropriate to replace a virtual machine with a virtual machine?
How to edit special effects in VR panorama? How to display detailed functions?
Error when starting PHP: [pool www] cannot get uid for user '@php_ fpm_ [email protected]’
How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?
Rust controls Dajiang programmable UAV Tello
IFLYTEK active competition summary! (12)
In depth understanding of jetpack compose kernel: slottable system
lvm-snapshot:基于LVM快照的备份
76页智慧物流园区综合解决方案2022(附下载)
异步过渡方案—Generator
Combining online and offline, VR panorama is a good way to transform furniture online!