当前位置:网站首页>Redis problem (I) -- cache penetration, breakdown, avalanche
Redis problem (I) -- cache penetration, breakdown, avalanche
2022-06-12 06:19:00 【leo_ messi94】
Cache penetration
key The corresponding data does not exist in the data source , Each time for times key The request for could not be fetched from the cache , Requests are pushed to the data source , That could crush the data source .

For example, use a non-existent user id To get user information , There is no such data in the cache or database , Hackers may use this vulnerability to attack and overwhelm the database
The goal is to crash the server
What happened
- The pressure on the application server has increased
- redis Hit rate reduced
- Keep querying the database
The reason for this
- redis No data in , There's nothing in the database
- There are a lot of anomalies url visit
Solution
There must be no data that cannot be cached or queried , Because the cache is written passively on Miss , And for the sake of fault tolerance , If the data cannot be queried from the storage tier, the cache will not be written , This will cause the non-existent data to be queried by the storage layer every time it is requested , It loses the meaning of caching .
- Cache null values : If the data returned by a query is empty ( Whether or not the data does not exist ), We still cache this empty result , Setting the expiration time for empty results can be very short , Not more than 5 minute
- Set up an accessible list ( White list ): Use bitmaps Type defines a list of accessible , list id As bitmaps The offset , Every visit and bitmap Medium id Compare , If you visit id be not in bitmaps in , To intercept , Access not allowed .
- Use of Blum filter : The bloom filter is actually a very long binary vector ( Bitmap ) And a series of random mapping functions (hash function ). The bloom filter can retrieve whether an element is in a collection . Its advantage is that the space efficiency and query time are far more than the general algorithm , The disadvantage is that it has certain error recognition rate and deletion difficulty
- Real-time monitoring : If I found redis It's starting to drop , Need to check access objects and data , Cooperate with operation and maintenance personnel , You can set up a blacklist to restrict services
Cache breakdown
key The corresponding data exists , But in redis Medium overdue , At this time, if a large number of concurrent requests come , These requests are read from the database and set back to the cache , At this time, a large amount of concurrency may overwhelm the database .
What happened
- Database access pressure increases instantaneously
- redis Not in a large number key Be overdue
- redis The normal operation
The reason for this
- redis One of them key Out of date , At the same time the key Be visited a lot
Solution
key It may be accessed at some point in time with super high concurrency , Is a very popular data . At this time, we need to consider a problem : The problem of cache breakdown .
- Preset hot data : stay redis Before the peak visit , Put some hot data into redis in , Increase these hot key Duration
- Timely adjustment : On site monitoring of those data is popular , Adjust expiration time in real time
- Using locks :
- When the cache fails ( The value is empty ), Not immediately load db
- First, use the caching tool to perform some operations with the return value of successful operations ( such as setnx)
Cache avalanche
key The corresponding data exists , But in redis Medium overdue , At this time, if a large number of concurrent requests come , These requests are read from the database and set back to the cache , At this time, a large amount of concurrency may overwhelm the database .
The difference between cache avalanche and cache breakdown is cache avalanche For many key cache .

What happened
The pressure on the database increases and the server crashes
The reason for this
In a very small period of time , A lot of key The centralized expiration of
terms of settlement
- Building a multi-level cache architecture :nginx cache +redis cache + Other caches
- Use locks or queues : Lock or queue is used to ensure that there will not be a large number of threads reading and writing to the database at one time , So as to avoid a large number of concurrent requests falling on the underlying storage system in case of failure . Not for high concurrency
边栏推荐
- 468. verifying the IP address
- Leetcode 第 80 场双周赛题解
- Sensor bringup 中的一些问题总结
- Tips for using the potplayer video player
- 为什么联合索引是最左匹配原则?
- Bulk Rename Utility
- Leetcode sword finger offer (Second Edition) complete version of personal questions
- Simple spiral ladder generation for Houdini program modeling
- Storing texture2d to hard disk JPG file with script under unity3d
- Video summary with long short term memory
猜你喜欢

数据库为什么不使用hash表?

摄像头拍摄运动物体,产生运动模糊/拖影的原因分析

Findasync and include LINQ statements - findasync and include LINQ statements

IDEA常用配置

Guns框架多数据源配置,不修改配置文件

Leetcode personal question solution (Sword finger offer3-5) 3 Duplicate number in array, 4 Find in 2D array, 5 Replace spaces

Touch screen setting for win7 system dual screen extended display

Project technical structure

夜神模拟器adb查看log

Bulk Rename Utility
随机推荐
(UE4 4.27) UE4 adds a customized meshpass to realize the edge illumination of the mobile terminal
On the normalization of camera rotation interpolation
Leetcode-1260. 2D mesh migration
468. verifying the IP address
Unity3d script captures a sub area from the screen and saves it as texture2d, which is used to save pictures and maps
Poisson disk sampling for procedural placement
Excel VBA opens a file that begins with the specified character
相机图像质量概述
English语法_副词_有无ly,意义不同
How to increase heap size of JVM [duplicate] - how to increase heap size of JVM [duplicate]
Directx11 advanced tutorial cluster based deffered shading
Sqlite Cross - compile Dynamic Library
Understand Houdini's (heightfield) remap operation
The unity3d script searches for colliders with overlaps within the specified radius
为什么数据库不使用二叉树、红黑树、B树、Hash表? 而是使用了B+树
Word vector training based on nnlm
为什么联合索引是最左匹配原则?
(UE4 4.27) customize globalshader
2D human pose estimation for pose estimation - pifpaf:composite fields for human pose estimation
N-degree Bessel curve