当前位置:网站首页>Redis cache penetration, cache breakdown, cache avalanche
Redis cache penetration, cache breakdown, cache avalanche
2022-04-23 20:07:00 【Handsome that handsome】
Although we are using redis It's very cool when caching , It greatly improves the performance and efficiency of our applications , Especially in data query , We don't need to query data in the persistent database directly , Instead, you can query data in memory
There are always two sides to everything , While using it well , We must also face the problems it brings , It's about data consistency , This problem , It's a matter of weighing the pros and cons , Let's go on
redis When the cache is used with some persistent databases , There will be some high availability problems , Such as :
- Cache penetration
- Cache breakdown
- Cache avalanche
We can solve the above problems , That solves the problem of high availability of some servers
What is cache penetration
Let's learn some first , On the underlying principles and actual source code analysis , Let's watch it later
Cache penetration , That is, the user wants to query a data , stay redis Can't find , That is, no hits in the cache , Then it will be directly de persistent mysql Query in , There is no such data , Then this query fails
When there are many users , The query cache did not find , Then all these are to query the persistent mysql database , All the pressure hit mysql above , This is cache penetration
The solutions are generally 2 Ways of planting
- Using the bloon filter
- Cache empty objects
Using the bloon filter
A bloom filter is a data structure , For all possible query parameters, use hash How to store , It will be verified at the control layer first , If it doesn't fit , Then discard , This avoids the pressure on the underlying storage system
Bloom filters are deployed in redis In front of , To intercept data , Reduce to redis The impact of , Thus reducing the impact on Impact of persistence layer
Cache empty objects
Caching empty objects , That is, when we do not query the data we expect in the persistent database , Then an empty object is returned , And cache the empty object , Then set an expiration time
When there is a request to access this object later , The cache can directly access the empty object , This protects the persistent data layer , Reduce the impact pressure on him
By caching empty objects as described above , It seems to solve the problem , But use lasts , Will find key Values correspond to more and more empty objects , There will be the following 2 A question
- Very many empty objects are cached , Then there are many corresponding key Occupy Memory space , Occupancy resources , Memory pressure rises sharply
- If the expiration time of an empty object is up , Then the pressure of the request will still hit the persistent database , This will affect the consistency of data business
What is cache breakdown
Cache breakdown occurs when the amount of data is too large , Or the cache has expired
When a key At the moment of expiration , There are a lot of requests for this key The data of , This kind of data is hot data , Because at the moment when the cache expires , The request will also access the persistent database to query the data , And the data will be written to the cache , At this point, it will lead to excessive pressure on the database in an instant , Cause breakdown
It can be understood here that The difference between breakdown and penetration :
breakdown , It's a key Very hot , A lot of interviews are in this key above , stay key The moment of failure , All requests are typed on the database , Just make a hole , Breakdown
Penetration is more about the absence of accessed data , A large number of requests for access are non-existent data
Buffer breakdown solution
- Set hotspot data to not expire , Do not set expiration time , There will be no hot spots key The moment of expiration causes problems
- Plus distributed locks , Guarantee for every key , At the same time, there is only one service to access , Other services did not get the lock , You can't access redis This key, Then you need to wait to get the lock
This way, , The pressure of the lock is very great , visit redis Access the lock first , Equivalent to locking to redis Blocked a layer
What is a cache avalanche
Cache avalanche Is in a certain period of time , Cache set expired , perhaps redis Downtime can occur
for example :
In some hot events , Some goods will be set to expire within a fixed time , So in redis Inside , This fixed point in time , a large number of key Be overdue , This leads to... During this time period Cache failed ,
And a large number of request data are printed on the persistent database , It's hard , Under this pressure peak , The pressure is all on the persistent database , This will cause the persistent database to go down
The above ,key The problem of centralized expiration is not very painful , What hurts most is redis It's down. , Natural periodic peak pressure , Our persistent database can withstand the pressure , It happened to be redis Abnormal downtime , Hang one piece at a time , This is likely to hang up all the persistent databases in the rear , This is a devastating crushing
Cache avalanche solution :
- take redis Make it highly available
build redis colony , Different live , Since I'm worried redis Can hang , Then let's prepare more redis , Make it active and standby , Or live more in a different place - Current limiting the drop
When the cache fails , Restrict the order of accessing data by locking , Or turn off some unimportant Services , Let resources and performance fully provide our main services - Do data preheating
Data preheating is before we officially go online , Let's first access the data we need to access in advance , In this way, a large amount of data to access the database can be written to the cache
In this way, you can manually trigger and load different data before the upcoming high concurrency data access key , And different expiration times will be set , The main thing is to balance the cache invalidation , In this way, try to avoid losing a lot of key Focus on overdue situations
版权声明
本文为[Handsome that handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210557450646.html
边栏推荐
- Video understanding
- Grafana shares links with variable parameters
- aqs的学习
- Mysql database - connection query
- NC basic usage 1
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- FFT物理意义: 1024点FFT就是1024个实数,实际进入fft的输入是1024个复数(虚部为0),输出也是1024个复数,有效的数据是前512个复数
- [numerical prediction case] (3) LSTM time series electricity quantity prediction, with tensorflow complete code attached
- STM32 Basics
- Distinction between pointer array and array pointer
猜你喜欢
Compact CUDA tutorial - CUDA driver API
Virtual machine performance monitoring and fault handling tools
山大网安靶场实验平台项目-个人记录(五)
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (6)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(八)
如何在BNB鏈上創建BEP-20通證
Unity general steps for creating a hyper realistic 3D scene
The textarea cursor cannot be controlled by the keyboard due to antd dropdown + modal + textarea
【数值预测案例】(3) LSTM 时间序列电量预测,附Tensorflow完整代码
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
随机推荐
Go recursively loops through folders
MFCC: Mel频率倒谱系数计算感知频率和实际频率转换
腾讯邱东洋:深度模型推理加速的术与道
Mysql database - connection query
nc基础用法
R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线、自定义计算交叉点、自定义配置indifference函数的参数丰富可视化效果
Unity创建超写实三维场景的一般步骤
Use test of FFT and IFFT library functions of TI DSP
MySQL 进阶 锁 -- MySQL锁概述、MySQL锁的分类:全局锁(数据备份)、表级锁(表共享读锁、表独占写锁、元数据锁、意向锁)、行级锁(行锁、间隙锁、临键锁)
ESP8266-入门第一篇
SRS deployment
VeraCrypt文件硬盘加密使用教程
[text classification cases] (4) RNN and LSTM film evaluation Tendency Classification, with tensorflow complete code attached
Compact CUDA tutorial - CUDA driver API
Speex Wiener filter and rewriting of hypergeometric distribution
Openharmony open source developer growth plan, looking for new open source forces that change the world!
深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件
Remote code execution in Win 11 using wpad / PAC and JScript
NC basic usage 3
基于pytorch搭建GoogleNet神经网络用于花类识别