当前位置:网站首页>Linux Redis cache avalanche, breakdown, penetration
Linux Redis cache avalanche, breakdown, penetration
2022-08-04 08:08:00 【1 2 3 Chasing dreams together】
1, cache avalanche
1.1 Causes
One, simply put, there was a problem in the design of the cache at that time, which caused most of the cached data to expire in large quantities at the same time.This will put all the pressure on the database.
2. The Redis cache instance fails and goes down.
1.2 Solutions
1. Solve the central failure of hotspot data
The following solutions can be used to solve the cache avalanche problem caused by the failure of a large number of data sets:
- Uniform expiration: Set different expiration times for hotspot data, and add a random value to the expiration time of each key;
- Set the hotspot data to never expire: do not set the expiration time, if there is an update, you need to update the cache;
- Service downgrade: refers to the different processing methods of the service for different data:
- The business accesses non-core data and directly returns predefined information, null value or error;
- If the business accesses the core data, it is allowed to access the cache. If the cache is missing, the database can be read.
2. Solve the problem of Redis instance downtime
Option 1: Implement service fuse or request current limiting mechanism
We monitor the load indicators of Redis and the server where the database instance is located. If the Redis service is found to be down, the load pressure of the database will increase., we can start the service circuit breaker mechanism to suspend access to the cache service.
However, this method has a greater impact on business applications, and we can also reduce this impact by limiting current.
For example: For example, when the business system is running normally, the maximum number of incoming requests per second by the request portal is 10,000, of which 9,000 requests can be processed by the cache, and the remaining 1,000 requests will be sent to the database for processing.
Once an avalanche occurs, the number of requests processed by the database per second suddenly increases to 10,000. At this time, we can start the current limiting mechanism.At the front-end request entry, only 1000 requests per second are allowed, and the others are directly rejected.This avoids sending a large number of concurrent requests to the database.
Option 2: Pre-prevention
Build a Redis cache highly reliable cluster through master-slave nodes.If the master node of the Redis cache fails, the slave node can also switch to become the master node and continue to provide cache services, avoiding the cache avalanche problem caused by the downtime of the cache instance.
2, cache penetration
2.1 Causes
Cache penetration means that the data to be accessed by the user is neither in the cache nor in the database, causing the user to check the database every time they request the data, and then return empty.If malicious attackers continuously request data that does not exist in the system, it will cause excessive pressure on the database, which will seriously overwhelm the database.
2.2 Solutions
- The interface layer adds verification: user authentication, parameter verification (whether the request parameter is legal, whether the request field does not exist, etc.);
- Cache null/default value: When cache penetration occurs, we can cache a null value or default value in Redis (for example, the inventory default value is 0), which avoids sending a large number of requests toDatabase processing, maintaining the normal operation of the database.There are two problems with this approach:
- If there are a large number of key penetrations, the cached empty objects will occupy precious memory space.In this case, you can set an expiration time for the empty object.After the expiration time is set, the cache may be inconsistent with the database.
- Bloom filter: Quickly determine whether the data exists, avoid querying whether the data exists from the database, and reduce the pressure on the database.
3, cache breakdown
3.1 Causes
For a hot key, at the moment when the cache expires, a large number of requests come in. Since the cache expires at this time, the requests will eventually go to the database, resulting in a large amount of instantaneous database requests and a sudden increase in pressure, resulting inThe database is at risk of being hit.
3.2 Solutions
1. Add mutex lock.When a large number of requests flood in after the hotspot key expires, only the first request can acquire the lock and block. At this time, the request queries the database, writes the query result to redis, and releases the lock.Subsequent requests go directly to the cache.
2. Set the cache not to expire or there are threads in the background to renew the hot data all the time.
边栏推荐
- 通过GBase 8c Platform安装数据库集群时报错
- 分布式计算实验4 随机信号分析系统
- 关于#sql#的问题:后面换了一个数据库里面的数据就不能跑了
- Secondary network security competition C module MS17-010 batch scanning
- 研究性学习专题 3_LL(1)语法分析设计原理与实现
- [STM32] STM32F103 series name and package, memory
- 千万级别的表分页查询非常慢,怎么办?
- 电脑系统数据丢失了是什么原因?找回方法有哪些?
- Typora颜色公式代码大全
- 实现加载驱动、得到数据库对象、关闭资源的代码复用,将代码提取到相应的工具包里边。优化程序
猜你喜欢
随机推荐
线程安全问题
虚拟机没有USB网卡选项怎么解决
【论文笔记】—低照度图像增强—Supervised—RetinexNet—2018-BMVC
[Computer recording screen] How to use bandicam to record the game setting graphic tutorial
设计信息录入界面,完成人员基本信息的录入工作,
Typora颜色公式代码大全
TCP协议详解
分布式计算实验3 基于PRC的书籍信息管理系统
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
一天学会JDBC06:PrepaerdStatemtnt
在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster”。这是为什么呢?有什么解决办法?
解决循环依赖import cycle not allowed的最佳解决办法
MySQL 8.0.29 详细安装(windows zip版)
ShuffleNet v2网络结构复现(Pytorch版)
通过GBase 8c Platform安装数据库集群时报错
MySQL BIGINT 数据类型
高等代数_证明_两个矩阵乘积为0,则两个矩阵的秩之和小于等于n
LeetCode 135. 分发糖果
大佬们,mysql里text类型的字段,FlinkCDC需要特殊处理吗 就像处理bigint uns
第一次用postgreSQL,想装主从,用的12.7 tar.gz版本。安装好后没在 share目录下找到样例配置recovery.conf.sample,是安装方式不对,还是路径不对?