当前位置:网站首页>Cache penetration, cache breakdown, cache avalanche and Solutions
Cache penetration, cache breakdown, cache avalanche and Solutions
2022-07-29 05:07:00 【Doghead Intern】
redis It's a kind of NoSql High speed slow K-V Save the database , Can achieve fast access .
redis More suitable for storage Session Information 、 cache 、 Ranking List 、 Message queue 、 Friends and counters
redis Cache penetration
redis Cache penetration refers to querying data that must not exist , But there is no such data in the cache , You need to query from the database , And there is no such data in the database , So it will not be written to redis in , This leads to querying the database every time you access the nonexistent data , This leads to cache penetration .
terms of settlement :
Cache null values , If the data cannot be queried from the database , We can set a null value with a short expiration time to be stored in redis in
Using interceptors , Judge the accessed data , Shield the data that must not exist .
Use of Blum filter , Use a larger bitmap To filter key.
The bloon filter
The working principle of Bloom filter is well understood , Is to store objects in a hash table , To judge whether the object exists . In order to improve judgment , Multiple hash functions can be used for hash distribution .
Collective implementation method of Bloom filter , Pass an object through multiple hash functions , Get different hash values , And then bitmap The position in is determined by 0 Set as 1, For example, one Tom There may be three hash functions , Exist in sixteen spaces bitmap in , Location may be 3,5,15.
The reason why objects need to be hashed many times is , Different objects , After the same hash function , The hash value may be the same , That is to say Hash collision , So we need to try to reduce this possibility .
So to sum up , If we want to judge whether an object exists , You need to pass the object through the hash function in turn , Calculate the hash value , As long as bitmap There is a position in 0, Then the object must not exist . If all positions of the object are 1, Then the object may exist ( Hash collision may cause us to misjudge ).
redis Cache breakdown
Cache breakdown is a special case of cache avalanche , It refers to a hot data , At the moment the cache expires , There are a lot of requests to access this data , Cause breakdown to DB, cause DB Too much pressure on me .
resolvent
Use synchronized+ Double check mechanism , Take data from DB Is written to the cache , reduce DB pressure .
Never expired data settings
Redis Cache avalanche
Cache avalanche means that the cache concentration disappears within a period of time , Cause a lot of cache breakdown , thus DB Too much pressure load .
resolvent
Use synchronized+ Double check mechanism , Control the number of reads from the database and writes to the cache by locking , Some key Only one thread is allowed to query and write to the cache , Other threads wait .
Add a random value to the cache expiration time , Reduces cache expiration at the same time .
Cache preheating , Avoid projects starting , The cache is empty , Cause a lot of requests to DB, Load the data into the cache in advance .
边栏推荐
- Sguard64.exe ace guard client exe: frequent disk reading and writing, game jamming, and Solutions
- 2022杭电多校联赛第四场 题解
- Solve the warning prompt of MySQL mapping file
- 1 句代码,搞定 ASP.NET Core 绑定多个源到同一个类
- Google gtest事件机制
- How does excel filter out the content you want? Excel table filtering content tutorial
- 让你的正则表达式可读性提高一百倍
- stack和queue和优先级队列(大堆和小堆)模拟实现和仿函数讲解
- What if excel is stuck and not saved? The solution of Excel not saved but stuck
- Conv1d of torch
猜你喜欢

Torch.nn.crossentropyloss() details

深度学习刷SOTA的一堆trick

What if excel is stuck and not saved? The solution of Excel not saved but stuck

The person who goes to and from work on time and never wants to work overtime has been promoted in front of me

Flink+iceberg environment construction and production problem handling

Quick start JDBC

On prepayment of house purchase

Flink+Iceberg环境搭建及生产问题处理

WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!

Unity Metaverse(三)、Protobuf & Socket 实现多人在线
随机推荐
Reply from the Secretary of jindawei: the company is optimistic about the market prospect of NMN products and has launched a series of products
Jackson解析JSON详细教程
虚拟偶像的歌声原来是这样生成的!
玩家访问网站自动弹窗加QQ群方法以及详细代码
1 句代码,搞定 ASP.NET Core 绑定多个源到同一个类
五个关联分析,领略数据分析师一大重要必会处理技能
EMI interference troubleshooting with near-field probe and current probe
力扣------对奇偶下标分别排序
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
2022杭电多校联赛第四场 题解
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
MySQL regularly calls preset functions to complete data update
自贸经济中架起的“隐形桥梁”:国货精品与中国AI力量
Opencv learning 1 (environment configuration)
[config] configure array parameters
ODOO开发教程之透视表
深度学习刷SOTA的一堆trick
Google gtest事件机制
P5714 [deep foundation 3. Case 7] obesity
[2022 freshmen learning] key points of the third week