当前位置:网站首页>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.

边栏推荐
猜你喜欢

ECCV 2022 | Towards Data Efficient Transformer Object Detectors

Web3创始人和建设者必备指南:如何构建适合的社区?

MaxWell scraped data

吃透Chisel语言.28.Chisel进阶之有限状态机(二)——Mealy状态机及与Moore状态机的对比

Recommended open source tools: MegPeak, a high-performance computing tool

三电系统集成技术杂谈

一文读懂网络效应对Web3的重要意义
4 senior experts share the insider architecture design and implementation principles of Flink technology with years of experience in large factories

Start learning C language

Flink real-time data warehouse completed
随机推荐
ROS 导航
How to use Databricks for data analysis on TiDB Cloud | TiDB Cloud User Guide
4位资深专家多年大厂经验分享出Flink技术内幕架构设计与实现原理
MaxWell scraped data
泡沫褪去,DeFi还剩下什么
内容产品进化三板斧:流量、技术、产品形态
Mac 中 MySQL 的安装与卸载
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
JSON常用注解
新时代背景下智慧城市的建设与5G技术有何关联
Digital signal processing course lab report (what foundation is needed for digital signal processing)
The use of ccs software (app software that makes money reliably)
5. DOM
关于mariadb/mysql的user表:密码正确但登录失败,可能与mysql的空用户有关
学习 MySQL 需要知道的 28 个小技巧
Flink本地UI运行
JUC common thread pool source learning 02 ( ThreadPoolExecutor thread pool )
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
分布式限流 redission RRateLimiter 的使用及原理
LeetCode_数位枚举_困难_233.数字 1 的个数