当前位置:网站首页>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 .
边栏推荐
- How does excel filter out the content you want? Excel table filtering content tutorial
- Various configurations when pulsar starts the client (client, producer, consumer)
- 输入的查询SQL语句,是如何执行的?
- P2181 diagonal
- roLabelImg转DATO格式数据
- [wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]
- How to install Office2010 installation package? How to install Office2010 installation package on computer
- What are the core features of the digital transformation of state-owned construction enterprises?
- Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
- 学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置
猜你喜欢

What are the core features of the digital transformation of state-owned construction enterprises?

学习数据库的第一个程序

开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开

Flink+iceberg environment construction and production problem handling

How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally

What if the computer cannot open excel? The solution of Excel not opening

如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
Let you understand several common traffic exposure schemes in kubernetes cluster

Five correlation analysis, one of the most important skills of data analysts

网安学习-内网安全1
随机推荐
IOS interview preparation - IOS
MySQL定时调用预置函数完成数据更新
Excel怎么筛选出自己想要的内容?excel表格筛选内容教程
虚拟偶像的歌声原来是这样生成的!
如何安装office2010安装包?office2010安装包安装到电脑上的方法
How to install Office2010 installation package? How to install Office2010 installation package on computer
传奇开区网站如何添加流量统计代码
Box horizontal vertical center layout (summary)
缓存穿透、缓存击穿、缓存雪崩以及解决方法
Improve the readability of your regular expressions a hundred times
Wps如何使用智能填充快速填充数据?Wps快速填充数据的方法
What if excel is stuck and not saved? The solution of Excel not saved but stuck
Pivot table of odoo development tutorial
学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置
Operator operation list of spark
开区网站打开自动播放音乐的添加跟修改教程
WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!
Network Security Learning - Intranet Security 1
The most comprehensive promotion plan for the launch of new products
Solve the warning prompt of MySQL mapping file