当前位置:网站首页>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
边栏推荐
- 2022 review questions and mock exams for main principals of hazardous chemical business units
- 网站漏洞修复服务商分析可控参数带来的越权
- 神经网络和自动控制的联系
- Code learning (deamnet) CVPR | adaptive consistency prior based deep network for image learning
- Redis message subscription
- Why does the Fed cut interest rates benefit the digital money market in the long run? 2020-03-05
- 类型详解·自定义类型·结构体初识
- Facial key point detection CNN
- Xilinx ultrascale+ MPSoC (zu9eg/zu15eg) high performance PCIe data preprocessing board
- How to write the highlights of SCI papers (seriously teach you how to write)
猜你喜欢

1669. Merge two linked lists (merge of two linked lists)
![[C # variable constant keyword] - variable constants and keywords in C #](/img/9b/433f9110d9c7599d8beac8288ea409.png)
[C # variable constant keyword] - variable constants and keywords in C #
![[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine](/img/7e/ddf05e76da26e9b2d1fd1519703571.png)
[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine

The website vulnerability repair service provider analyzes the ultra vires caused by controllable parameters

DP dynamic planning enterprise level template analysis (Digital triangle, rising sequence, knapsack, state machine, compressed DP)

redis集群

Why does the Fed cut interest rates benefit the digital money market in the long run? 2020-03-05

Yolov5 label and establish your own data set

Code learning (deamnet) CVPR | adaptive consistency prior based deep network for image learning

【C语言】自定义类型详解:结构体、枚举、联合
随机推荐
Database review -- database recovery technology
[C console] - C console class
[C # variable constant keyword] - variable constants and keywords in C #
redis主从复制
通过ip获取归属地
FMC sub card: 4-way sfp+ 10 Gigabit optical fiber network FMC sub card
Niuke topic - house raiding 1, house raiding 2
才意识到自己“奇葩”的360,会不会有些晚?
Ku115 FPGA high performance 10G Optical fiber network hardware accelerator card / 2-way 10G Optical fiber data accelerator card
深圳保诚笔试记录
Export file or download file
Download, installation and use of mongodb
Convolutional neural network CNN
Leetcode daily question 2021/7/11-2021/7/17
If a number in C language is exactly equal to the sum of its factors, this number is called "perfect". For example, 6=1 + 2 + 3 programming
[MySQL] transaction: basic knowledge of transaction, implementation principle of MySQL transaction, detailed explanation of transaction log redolog & undo
[JVM] heap memory, escape analysis, on stack allocation, synchronous omission, scalar replacement details
redis集群
代码学习(DeamNet)CVPR | Adaptive Consistency Prior based Deep Network for Image Denoising
【flask入门系列】异常处理