当前位置:网站首页>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.
边栏推荐
- JSON common annotations
- 容器排序案例
- MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
- 一文读懂网络效应对Web3的重要意义
- EasyV数字孪生流域|宁波智慧水利整体智治综合应用
- Office Automation | Office Software and Edraw MindMaster Shortcuts
- Normal and escaped strings for postgresql
- 分布式限流 redission RRateLimiter 的使用及原理
- 4位资深专家多年大厂经验分享出Flink技术内幕架构设计与实现原理
- MaxWell scraped data
猜你喜欢
Flink实时数仓完结
Lock wait timeout exceeded solution
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Lock wait timeout exceeded解决方案
952. 按公因数计算最大组件大小 : 枚举质因数 + 并查集运用题
CVE-2022-33891 Apache Spark 命令注入复现
三电系统集成技术杂谈
Still saying software testing doesn't have a midlife crisis?9 years of test engineers were eliminated
A simple change for problem, knapsack problem sets of shell
MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
随机推荐
Mac 中 MySQL 的安装与卸载
Lock wait timeout exceeded solution
【Vue.js 3.0源码】KeepAlive 组件:如何让组件在内存中缓存和调度?
The website adds a live 2d kanban girl that can dress up and interact
Could not acquire management access for administration
Flink优化
4位资深专家多年大厂经验分享出Flink技术内幕架构设计与实现原理
【元胞自动机】基于元胞自动机模拟生命演化、病毒感染等实例附matlab代码
打破原则引入SQL,MongoDB到底想要干啥?
关于容器的小案例
MySql error: SqlError(Unable to execute query", "Can't create/write to file OS errno 2 - No such file...
Allure进阶-动态生成报告内容
JUC常见的线程池源码学习 02 ( ThreadPoolExecutor 线程池 )
双碳目标下:农田温室气体排放模拟
【云原生 • DevOps】influxDB、cAdvisor、Grafana 工具使用详解
PyQt5快速开发与实战 9.1 使用PyInstaller打包项目生成exe文件
The main content of terrain analysis (the special effect level of the wandering earth)
B+树索引页大小是如何确定的?
Flink real-time data warehouse completed
Lock wait timeout exceeded解决方案