当前位置:网站首页>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 .
边栏推荐
- Maxpool2d explanation -- Application in arrays and images
- The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?
- Ride: get picture Base64
- 基金销售行为规范及信息管理
- shell 同时执行多任务下载视频
- 2022-06-30: what does the following golang code output? A:0; B:2; C: Running error. package main import “fmt“ func main()
- Why should VR panoramic shooting join us? Leverage resources to achieve win-win results
- 基金客户和销售机构
- E-commerce seckill system
- In 2022, the latest JCR officially released the list of the latest global impact factors (top 600)
猜你喜欢

76页智慧物流园区综合解决方案2022(附下载)
![CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构](/img/ce/519778cd731f814ad111d1e37abd10.png)
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构

The girlfriend said: if you want to understand the three MySQL logs, I will let you heiheihei!

The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?

Which is better, server rental or hosting services in the United States?

206 page Shanghai BIM Technology Application and development report 2021

ABAQUS 2022 software installation package and installation tutorial
![[NLP] [textcnn] text classification](/img/bb/c8fd9f1ed458a88a17b8d5c70d9ce2.png)
[NLP] [textcnn] text classification

HP notebook disable touchpad after mouse is inserted

让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北
随机推荐
How do it outsourcing resident personnel position their pain points?
Shell multitasking to download video at the same time
How to close an open DNS resolver
76 page comprehensive solution 2022 for smart Logistics Park (download attached)
206 page Shanghai BIM Technology Application and development report 2021
Makefile notes (Yiwen Institute makefile)
Quick start of wechat applet -- project introduction
In depth understanding of jetpack compose kernel: slottable system
Code de conduite pour la vente de fonds et la gestion de l'information
Is it safe to open a stock account of Huatai Securities online?
Flitter - sort list sort
Manage edge browser settings (ie mode, homepage binding, etc.) through group policy in the enterprise
How to edit special effects in VR panorama? How to display detailed functions?
composer
LVM snapshot: preparation of backup based on LVM snapshot
What value should testers play in requirements review? Two minutes will stop you from being stupid
Asynchronous transition scenario - generator
C /platform:anycpu32bitpererrored can only be used with /t:exe, /t:winexe and /t:appcontainerexe
shell 同时执行多任务下载视频
Advanced mathematical modeling