当前位置:网站首页>Redis cache penetration and avalanche
Redis cache penetration and avalanche
2022-07-22 15:13:00 【Just number six Z】
Redis Cache penetration and avalanche
Cache penetration ( We can't find it )
The concept of cache penetration is simple , 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 , This is equivalent to cache penetration .
Solution
The bloon filter
A bloom filter is 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
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 .
problem :
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 still be 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 ( Too much , Cache expiration )
We need to pay attention to the difference between this and cache breakdown , Cache breakdown , It means a key Very hot , Constantly carrying big concurrency , Large concurrent centralized access to this point , When this key At the moment of failure , Continuous large concurrency breaks through the cache , Direct request database , It's like cutting a hole 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 access the database at the same time to query the latest data , And write back to the cache , Will cause the database transient pressure is too large .
Solution
Never expired data settings
At the cache level , Expiration time is not set , So there will be no hot spots key Problems after expiration
Add mutex lock
Distributed lock : Using distributed locks , Guarantee for each key At the same time, there is only one thread to query the back-end service , Other threads do not have permission to obtain distributed locks , So just wait , In this way, the pressure of high concurrency is transferred to distributed locks , So the test of distributed locks is great .
Cache avalanche
Cache avalanche , At a certain time , Expiration in cache set .
One of the reasons for the avalanche , For example, when writing this article , It's about double twelve o'clock , There will soon be a rush , This wave of commodity time is put into the cache , Suppose you cache for an hour . Then at one o'clock in the morning , The cache of this batch of goods has expired . And the access to this batch of products , It's all in the database , For databases , There will be periodic pressure peaks . So all the requests will reach the storage layer , The number of calls to the storage layer will skyrocket , Cause the storage layer to hang up .
Actually, the concentration is overdue , It's not very deadly , More deadly cache avalanche , It means that a node of the cache server is down or disconnected . Because of the cache avalanche formed naturally , Cache must be created in a certain time period , This is the time , The database can also withstand the pressure . It's just periodic pressure on the database . The cache service node is down , The pressure on the database server is unpredictable , It's likely to crush the database in an instant .
Solution
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 .( Different live )
Current limiting the drop (springcloud)
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 .
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 .
边栏推荐
- Millet box opens ADB debugging mode
- Design of ads multi frequency power amplifier bias network
- 2022-07-15 mysql接收新连接处理
- Worthington 胆碱酯酶,丁酰相关说明书
- Goodbye attention: a new paradigm for modeling users' long-term interests
- 【社媒营销】进来了解下Whatsapp Business API?出海群发不用愁!
- 如何围绕用户数字化运营?
- 2022-07-15 mysql/stone子查询内存拷贝分析及优化
- Worthington真菌分泌酶研究 丨半乳糖氧化酶方案
- With no performance forecast, BOE is silent at this time?
猜你喜欢
Simple use of Android kotlin
An East analysis sample
[independent station operation] Shopify sellers: how to improve the store experience? Two moves are done!
Worthington deoxyribonucleic acid and related research tools
Design of ads multi frequency power amplifier bias network
某视频app分析样本
How to make the signal of conductive slip ring better
Worthington peptide synthesis application chymotrypsin scheme
Analysis sample of a video app
2022-07-13 mysql/stonedb subquery optimizer processing record
随机推荐
Worthington cell separation optimization system (including cell separation guide)
Worthington植物原生质体制备丨纤维素酶方案
Worthington deoxyribonucleic acid and related research tools
shardingjdbc水平分表配置
How to make the signal of conductive slip ring better
1567. Length of the longest subarray whose product is a positive number ●●
Release time test
2022-07-18 jenkins流水线使用及创建自己的流水线
这个sql怎么优化?
10 baseline papers required for entry recommendation system
投票不能重复
Worthington 胆碱酯酶,丁酰相关说明书
【独立站运营】Shopify卖家:如何改善店铺体验?两招搞定!
Zcmu--1925: HX & XH's game (C language)
Millet box opens ADB debugging mode
How to operate around users' digitalization?
Redis使用Jedis操作
Excel file parsing
Excel文件解析
Redis----三大特殊数据类型、事务、整合、配置文件、持久化rdb和aof、发布订阅、主从复制(哨兵模式)、缓存穿透和雪崩