当前位置:网站首页>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 .
边栏推荐
- Combining online and offline, VR panorama is a good way to transform furniture online!
- Maxpool2d explanation -- Application in arrays and images
- How to close an open DNS resolver
- Thoughts on the future of data analysis in "miscellaneous talk"
- Bridge emqx cloud data to AWS IOT through the public network
- 76 page comprehensive solution 2022 for smart Logistics Park (download attached)
- Warmup preheating learning rate "suggestions collection"
- Manage edge browser settings (ie mode, homepage binding, etc.) through group policy in the enterprise
- Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
- 在指南针上买基金安全吗?
猜你喜欢

VR panorama adds contrast function to make the display of differentiation effect more intuitive!

How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?
![[leetcode] [SQL] notes](/img/8d/160a03b9176b8ccd8d52f59d4bb47f.png)
[leetcode] [SQL] notes

Fastjson V2 simple user manual

Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)

Software engineering best practices - project requirements analysis

Prospects of world digitalization and machine intelligence in the next decade

MaxPool2d详解--在数组和图像中的应用

IFLYTEK active competition summary! (12)

Analysis of 8253a register
随机推荐
Solutions to errors in installing OpenSSL for CentOS 6.3 x64 PHP 5.2.6 extensions
Asynchronous transition scenario - generator
Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical
LVM snapshot: backup based on LVM snapshot
Random ball size, random motion collision
What value should testers play in requirements review? Two minutes will stop you from being stupid
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
基金銷售行為規範及信息管理
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
2022-06-30: what does the following golang code output? A:0; B:2; C: Running error. package main import “fmt“ func main()
QQmlApplicationEngine failed to load component qrc:/main. qml:-1 No such file or directory
PS2 handle-1 "recommended collection"
Design e-commerce seckill system
conv2d详解--在数组和图像中的使用
Fund managers' corporate governance and risk management
Qt笔记(七十四)之QLineEdit指定输入类型
Don't worry about whether you can be a coder if you don't learn English well. Learn it first
Repetition is the mother of skill
网上开华泰证券的股票账户是否安全呢?
Software engineering best practices - project requirements analysis