当前位置:网站首页>How to solve cache avalanche, breakdown and penetration problems
How to solve cache avalanche, breakdown and penetration problems
2022-07-27 14:25:00 【Sword Saint without trace】
Work together , Grow up together ! This is my participation 「 Nuggets day new plan · 8 Yuegengwen challenge 」 Of the 1 God , Click to see the event details
Preface
Reids As a popular distributed cache , Cache penetration will be encountered in the actual production environment 、 Cache breakdown 、 Cache avalanche and other abnormal scenarios , In order to avoid the huge loss caused by the abnormality , We need to understand the causes of each exception and the corresponding solutions , To improve system reliability and availability .
Cache penetration
brief introduction
The data requested by the user does not exist in the cache or database , Users need to query the database every time they request data , This leads to frequent access to the background database , Database load pressure increases , This phenomenon is called cache penetration .
The reasons causing
explain :
- Massive access to nonexistent key, Causes the database to process a large number of requests
Solution
There are two ways to solve cache penetration , The first is to cache empty objects , The second is to use a bloom filter .
Caching empty objects
When data cannot be found in the database , Caching empty objects , Then set the expiration time for the cache of the empty object , Check again next time Data time , Get directly from the cache , Thus, the purpose of reducing the pressure on the database is achieved .
Program drawback
- The cache layer needs to provide more memory space to cache empty objects , Waste more memory space .
- Even set a short expiration time when caching empty objects , It will also lead to data inconsistency during this period .
The bloon filter
The Bronx filter will be explained in detail in the subsequent articles , This article does not elaborate .
Cache breakdown
brief introduction
Redis When there are some hot data in , That is, there are a large number of requests for concurrent access key-value data . Extreme hot spot key-value When the data suddenly fails , Cache misses cause frequent access to the background database , This phenomenon is called cache breakdown .
The reasons causing
explain : Hot data expired , Cause a large number of query requests to cross the cache , Direct query database .
Solution
There are two solutions to cache breakdown , The first is to set up key Never expire ; The second is to use distributed locks , Ensure that only one query request can reload hotspot data into the cache at the same time , such , Other threads only need to wait for the thread to finish running , You can restart from Redis Get data in .
Set up key Never expire
Setting hotspot key When , Do not give key Set the expiration time .
Distributed lock
For hot spots key Using distributed locks , When a large number of queries the same key The request of , Only one request can acquire the lock , Query the database , Then put the results into the cache , Then release the lock , here , Other requests waiting for locks can continue , At this time, there is data in the cache , So get the data directly from the cache and return , Does not query the database .
Cache avalanche
brief introduction
The data requested by the user does not exist in the cache or database , Users need to query the database every time they request data , This leads to frequent access to the background database , Database load pressure increases , This phenomenon is called cache penetration .
The reasons causing
explain :
- The first is a large number Key Expired at the same time
- The second is Redis fault
Solution
For the first kind of large Key At the same time
Set each key The expiration time of should be as different as possible , You can add a random length of time to the timeout , Make their failure points as evenly distributed as possible .
The heat data can never expire
For the second kind of Redis failure
- use Redis Deployment of several high availability solutions , For the specific deployment plan, please refer to what I wrote before Redis High availability architecture .
summary
This article explains the avalanche of caching 、 breakdown 、 Causes and solutions of penetration problems , If you have any questions , Please feel free to give feedback .
边栏推荐
- A Keypoint-based Global Association Network for Lane Detection
- Converter registration of easyexcel
- Charles tutorial
- Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
- 基于在线问诊记录的抑郁症病患群组划分与特征分析
- Vscode -- create template file
- 网上券商APP开户安全有保障吗?
- Windows10 installing SQL Server 2019
- 平板模切机
- Document translation__ Tvreg V2: variational imaging method for denoising, deconvolution, repair and segmentation (part)
猜你喜欢

在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机

文献翻译__基于自适应全变差L1正则化的椒盐图像去噪

基于预训练模型的多标签专利分类研究

Good architecture is evolved, not designed

Pure C handwriting thread pool

Leetcode · daily question · 592. fraction addition and subtraction · simulation

灵活易用所见即所得的可视化报表

第3章业务功能开发(添加线索备注,自动刷新添加内容)

面试八股文之·TCP协议

阿里最新股权曝光:软银持股23.9% 蔡崇信持股1.4%
随机推荐
Rtl8762dk environment construction (I)
Download address of each version of libtorch
次小生成树【模板】
微策生物IPO过会:年营收12.6亿 睿泓投资与耀合医药是股东
Navicate报错access violation at address 00000000
Blocking queue
Shell编程规范与变量
JS什么是声明提前?函数与变量声明提前的先后顺序(执行上下文铺垫篇)
Research on automatic classification of electronic medical records based on unbalanced data
SLAM综述阅读笔记四:A Survey on Deep Learning for Localization and Mapping: Towards the Age of Spatial 2020
Why does script file 'd:\anaconda3\envs\pad appear_ env\Scripts\pip-script. py‘ is not present.
Flexible and easy to use WYSIWYG visual report
[luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging
达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
线程知识总结
Vscode -- create template file
Zhishang technology IPO meeting: annual revenue of 600million, book value of accounts receivable of 270Million
文献翻译__tvreg v2:用于去噪、反卷积、修复和分割的变分成像方法(部分)
[training day4] anticipating [expected DP]
This points to problems, closures, and recursion