当前位置:网站首页>Redis cache avalanche, penetration, breakdown
Redis cache avalanche, penetration, breakdown
2022-07-19 08:10:00 【Program three two lines】
One 、 through
1、 What is penetration
The user wants to query a data , Find out redis Memory databases don't have , That is, cache miss , So query the persistence layer database . There is no , So this query failed . When there are a lot of users , No cache hits , So they all went to the persistence layer database . This will put a lot of pressure on the persistence layer database , This is equivalent to cache penetration .
2、 Solution
programme 1: The bloon filter
It's a data structure , For all possible query parameters, use hash stored , Check at the control level first , If not, discard , Thus, the query pressure on the underlying storage system is avoided
programme 2: Caching empty objects
When the storage tier misses , Even empty objects returned are cached , At the same time, an expiration time will be set , Then accessing this data will get from the cache , Protected back-end data sources ;
But there are two problems with this approach :
1、 If null values can be cached , This means that the cache needs more space to store more keys , Because there may be a lot of empty keys ;
2、 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 .
programme 3: Set up an accessible list
Use bitmap Type defines a list of accessible , list id As bitmaps Offset , Every visit and bitmap Inside id Compare , If you visit id be not in bitmaps Inside to intercept
programme 4: Real-time monitoring
Find out redis The hit rate began to decrease rapidly Configure access objects and data Set blacklist restrictions
Two 、 breakdown
1、 What is breakdown

It means a key Very hot , Constantly carrying big concurrency , Large concurrent set Access this point , When this key At the moment of failure , Continuous large concurrency breaks through the cache , Direct request database , Like in a A hole was cut in a barrier . When a key At the moment of expiration , There are a lot of requests for concurrent access , This kind of data is generally hot data , Due to cache expiration , Will visit at the same time Ask the database for the latest data , And write back to the cache , Will cause the database transient pressure is too large .
2、 Solution
1、 Preset hot data :redis Before the summit visit , Put some hot data into redis Inside , Increase the of these popular data key Long time
2、 Real time adjustments : What data is hot on the spot , Real time adjustments key Expiration time
3、 Using locks :
When the cache fails ( Judge that the value is empty ), Not immediately load db;
First, use some operations of the caching tool with the return value of successful operations, such as redis Of SETNX
3、 ... and 、 Cache avalanche problem
1、 What is a cache avalanche
Cache avalanche : A large amount of data at the same time key Centralized expiration of , Request all forwarding To DB,DB Avalanche with excessive instantaneous pressure . The server crashed
2、 Solution
1、 Building a multi-level cache architecture :nginx cache +redis cache + Other caches
2、 Use locks or queues : Lock or queue to ensure that there will not be a large number of threads reading and writing to the database at one time , Avoid a large number of concurrent requests falling on the underlying storage system when it fails , Not for high concurrency
3、 Set expiration flag to update cache : Record whether the cache data is out of date ( Set the lead amount ), If it expires, it will trigger another thread to update the actual situation in the background key The cache of
4、 Spread the cache expiration time : For example, you can add a random value to the original failure time , such as 1-5 Minutes at random , In this way, the expiration time repetition rate of each cache will be reduced , It's hard to trigger a collective failure
边栏推荐
- Array exercise 3
- Visual Studio 生产环境配置方案:SlowCheetah
- STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏
- Jd.com's purchase intention forecast (III)
- the max_ iter was reached which means the coef_ did not converge “the coef_ did not converge“
- Ruffian Heng embedded bimonthly issue 58
- 剑指 Offer 42. 连续子数组的最大和-动态规划法
- Xinlinx zynq7010 domestic replacement fmql10s400 national production arm core board + expansion board
- 牛客题目——打家劫舍一、打家劫舍二
- Kingbasees can realize any of MySQL by constructing an aggregate function_ Value function.
猜你喜欢
![[MySQL] mvcc: correctly understand mvcc and its implementation principle](/img/00/71712ab114500384b96e0648740cac.png)
[MySQL] mvcc: correctly understand mvcc and its implementation principle

Stm32f103c8t6 hardware IIC control 4-pin 0.96 inch OLED display
![[JVM] heap memory, escape analysis, on stack allocation, synchronous omission, scalar replacement details](/img/cd/b359a746da9e411590927963c0d2a7.png)
[JVM] heap memory, escape analysis, on stack allocation, synchronous omission, scalar replacement details

redis缓存雪崩、穿透、击穿
![Virtual machine stack of [JVM]](/img/7b/5d847112230adcac087b9d6071baed.png)
Virtual machine stack of [JVM]

STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏

Double index mechanism of redis source code analysis

How did "leek" give money to "sickle"? 2020-03-07

Xilinx ultrascale+ MPSoC (zu9eg/zu15eg) high performance PCIe data preprocessing board

Ruffian Heng embedded bimonthly issue 58
随机推荐
【特征工程】
本地存储 sessionStorage
How to use curl in Jenkins pipeline and process response results
Standard Version (release and changelog Automation)
High performance integrated video image processing board based on ultrascale FPGA + Huawei Hisilicon arm / fpga+arm
Using PCA to simplify data
History and value of forked coins | eth, BCH, BSV 2020-03-08
如何在 Jenkins Pipeline 中使用curl 并处理响应结果
没那么大的组合数
STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏
Machine learning interview questions (Reprinted)
从赌场逻辑,分析平台币的投资价值 2020-03-03
Redis jump table implementation principle & time complexity analysis
WPF 三维应用搭建(基础)
分叉币的发展史及价值|ETH、BCH、BSV 2020-03-08
redis事务
openvino机器学习初体验
Beijing Jiewen technology, an acquiring outsourcing service provider, transferred 60% of its shares for about 480million
[C# 类和对象]-C# 中的方法以及类和对象编程
Is there any cumulative error in serial communication and the requirements for clock accuracy