当前位置:网站首页>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 .
边栏推荐
- Flat die cutting machine
- 递归方法实现最大公约数
- How to test and decrypt the encryption interface
- West test Shenzhen Stock Exchange listing: annual revenue of 240million, fund-raising of 900million, market value of 4.7 billion
- Unity2d -- camera follow
- 面向流行性疾病科普的用户问题理解与答案内容组织
- 【论文精读】Grounded Language-Image Pre-training(GLIP)
- Download address of each version of libtorch
- A Keypoint-based Global Association Network for Lane Detection
- 阻塞队列BlockingQueue
猜你喜欢

Jing Xiandong and other senior executives of ant group no longer serve as Alibaba partners to ensure independent decision-making

Architecture - the sublimation of MVC

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

This points to problems, closures, and recursion

Vscode -- create template file
![[training day3] reconstruction of roads [SPFA]](/img/eb/4729954bf5c6c0dc85daed9ca127f7.png)
[training day3] reconstruction of roads [SPFA]

SLAM综述阅读笔记七:Visual and Visual-Inertial SLAM: State of the Art, Classification,and Experimental 2021

c语言分层理解(c语言数组)

JS 疫情宅在家,学习不能停,七千字长文助你彻底弄懂原型与原型链

Excellent basic methods of URL parsing using C language
随机推荐
万字详解 Google Play 上架应用标准包格式 AAB
Chapter 3 business function development (view clue details)
【多线程的相关内容】
Lesson 3: reverse word order
log4j2 jdbc appender
poj3461 Oulipo【KMP】
Chinese character style transfer --- antagonistic discriminative domain adaptation (L1)
SLAM综述阅读笔记六:基于图像语义的SLAM调研:移动机器人自主导航面向应用的解决方案 2020
在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机
Excellent basic methods of URL parsing using C language
Good architecture is evolved, not designed
Ncnn compilation and use pnnx compilation and use
Cognition -- classic of the road to success of hardware engineers
阻塞队列BlockingQueue
West test Shenzhen Stock Exchange listing: annual revenue of 240million, fund-raising of 900million, market value of 4.7 billion
Slam overview Reading Note 7: visual and visual intangible slam: state of the art, classification, and empirical 2021
网上券商APP开户安全有保障吗?
Travel notes from July 11 to August 1, 2022
How to test and decrypt the encryption interface
Hdu1422 revisits the world cup [DP]