当前位置:网站首页>Redis cache penetration, breakdown, avalanche and consistency issues
Redis cache penetration, breakdown, avalanche and consistency issues
2022-07-30 15:16:00 【Feifei Technology House】
1. Cache penetration
Cache penetration refers to querying a data that does not exist in the cache and database.In this case, the request will definitely hit the database, which may cause the database to go down.
There are two ways to solve this problem:
- Cache empty queries, but this will take up extra space
- Validation filters, such as bloom filters
Bloom Filter
Bloom filters are an efficient and space-saving way to perform relatively accurate existence verification. The underlying principle is to go through multiple layers of hash filtering.
Simply put, we maintain an array of hashes. For all existing key values, we will traverse them. For each key value, we use N hash functions to calculate the location to which it will be projected, so that we can onlyGot a filter of 01 array.
When a request comes, we will use N hash functions to calculate which bit of the array the requested key will be mapped to, and the request will be allowed to pass only if every bit is passed.

After the above steps, we can ensure that as long as the existing key value can pass, but it does not rule out that a small number of non-existing keys will pass the filter.
But we can change the expected value of the passing accuracy by adjusting the array length L and the number N of hash functions. If you are interested in the specific mathematical reasoning process, you can learn more.
2. Cache breakdown
Cache breakdown means that hot keys not in the cache but in the database are accessed a lot in a short period of time.
There are three ways to solve this problem:
- Set the hotspot key not to expire
- Add distributed lock
- Current limit
3. Cache Avalanche
Cache avalanche refers to cache failures in a certain period of time, causing all requests to go to the database, causing the database to crash.
To solve this problem, you can set a random expiration time.
4. Cache coherency issues
The mainstream approach to resolving database-cache inconsistencies is delayed double deletion.
The process of delayed double deletion is as follows:
- The update operation is familiar with deleting the Redis cache
- Update the data in the database later
- The update operation sleeps for a period of time
- The update operation deletes the Redis cache again
Let's analyze the meaning of each step step by step:
- Delete the Redis cache for the first time: This is to prevent the dirty data in Redis from being read by read requests when the update operation is updating the MySQL database.
- Delete the Redis cache again: This is to prevent the update operation from deleting the Redis cache for the first time, a read request arrives at MySQL prior to the update request, and the dirty data is read to the Redis cache again.
- Sleep for a period of time: This is to prevent the update operation from deleting the Redis cache for the first time, a read request arrives at MySQL prior to the update request, but the Redis cache is deleted again later than the update operation, causing the Redis cache to be updated again to become dirtydata.

边栏推荐
- canal抓取数据
- Chapter6 : Has Artificial Intelligence Impacted Drug Discovery?
- Ts是什么?
- The use of ccs software (app software that makes money reliably)
- SQL 优化这么做就对了!
- ToDesk版本更新,引入RTC传输技术,是否早以替代向日葵远程控制?
- Some thoughts on String
- Huawei's 7-year-experienced software testing director, gives some advice to all friends who want to change careers to learn software testing
- PyQt5快速开发与实战 9.1 使用PyInstaller打包项目生成exe文件
- 5G-based Warehousing Informatization Solution 2022
猜你喜欢

Kubernetes应用管理深度剖析

Flink optimization

Redis 缓存穿透、击穿、雪崩以及一致性问题

SQL 优化这么做就对了!

English语法_不定代词 - both / either / neither

PyQt5快速开发与实战 9.1 使用PyInstaller打包项目生成exe文件

The highest level of wiring in the computer room, the beauty is suffocating

MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)

Metaverse Post Office AI space-themed series of digital collections will be launched at 10:00 on July 30th "Yuanyou Digital Collection"

A simple change for problem, knapsack problem sets of shell
随机推荐
Flink优化
Web3创始人和建设者必备指南:如何构建适合的社区?
[深入研究4G/5G/6G专题-46]: 5G Link Adaption链路自适应-2-常见缩略语
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Meta首份元宇宙白皮书9大看点,瞄准80万亿美元市场
开始学习C语言了
Use of SLF4J
CVE-2022-33891 Apache Spark 命令注入复现
吃透Chisel语言.28.Chisel进阶之有限状态机(二)——Mealy状态机及与Moore状态机的对比
算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面
Flink本地UI运行
LeetCode_数位枚举_困难_233.数字 1 的个数
JSON常用注解
About the data synchronization delay of MySQL master-slave replication
This editor actually claims to be as fast as lightning!
Recommended open source tools: MegPeak, a high-performance computing tool
localhost与127.0.0.1
The use and principle of distributed current limiting reduction RRateLimiter
关于容器的小案例
Lock wait timeout exceeded solution