当前位置:网站首页>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
边栏推荐
- PDF. js FAQs
- Introduction to the method of diligently searching for the alliance procedure
- 为什么数据库不使用二叉树、红黑树、B树、Hash表? 而是使用了B+树
- Leetcode 第 80 场双周赛题解
- 关于 Sensor flicker/banding现象的解释
- 哈工大信息内容安全实验
- MLP sensor
- Why do I object so [1.01 to the power of 365 and 0.99 to the power of 365]
- Poisson disk sampling for procedural placement
- Research Report on truffle fungus industry - market status analysis and development prospect forecast
猜你喜欢

分段贝塞尔曲线
![How to increase heap size of JVM [duplicate] - how to increase heap size of JVM [duplicate]](/img/65/a214d137e230b1a1190feb03660f2c.jpg)
How to increase heap size of JVM [duplicate] - how to increase heap size of JVM [duplicate]

User login (medium)

Tips for using the potplayer video player

Jetson TX2 machine brushing jetpack4.2 (self test successful version)

Word2Vec

Redis queue

. Net core - pass Net core will Net to cross platform

姿态估计之2D人体姿态估计 - PifPaf:Composite Fields for Human Pose Estimation

cv2.fillPoly coco annotator segment坐标转化为mask图像
随机推荐
Nocturnal simulator ADB view log
EBook list page
Word vector training based on nnlm
MNIST handwritten data recognition by CNN
Bulk Rename Utility
Unity3d display FPS script
cv2.fillPoly coco annotator segment坐标转化为mask图像
Idea common configuration
Leetcode-93. Restore IP address
Video fire detection based on Gaussian mixture model and multi-color
Explanation of sensor flicker/banding phenomenon
Dlib face detection
Get the size of the picture
Book classification based on Naive Bayes
How do I get the date and time from the Internet- How to get DateTime from the internet?
Leetcode-1535. Find the winner of the array game
Understand Houdini's (heightfield) remap operation
为什么数据库不使用二叉树、红黑树、B树、Hash表? 而是使用了B+树
Image processing: image[:,:,:: -1], image[:,: -1,:], image[:,: -1,:]
LeetCode-剑指Offer(第二版)个人题解完整版