当前位置:网站首页>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.
边栏推荐
- 第一次用postgreSQL,想装主从,用的12.7 tar.gz版本。安装好后没在 share目录下找到样例配置recovery.conf.sample,是安装方式不对,还是路径不对?
- redis---分布式锁存在的问题及解决方案(Redisson)
- 分布式计算实验1 负载均衡
- 推荐几种可以直接翻译PDF英文文献的方法
- 解决:Hbuilder工具点击发行打包,一直报尚未完成社区身份验证,请点击链接xxxxx,项目xxx发布H5失败的错误。
- 经典动态规划问题的递归实现方法——LeetCode39 组合总和
- Secondary network security competition C module MS17-010 batch scanning
- 【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
- leetcode 22.7.31(1)两数之和 (2)整数除法
- The difference between character stream and byte stream
猜你喜欢
智汇华云 | 华云软件定义网络 DCI介绍
线程安全问题
[STM32] STM32F103 series name and package, memory
推荐几种可以直接翻译PDF英文文献的方法
【UE虚幻引擎】UE5三步骤实现AI漫游与对话行为
【电脑录制屏】如何使用bandicam录游戏 设置图文教程
[Computer recording screen] How to use bandicam to record the game setting graphic tutorial
data:image/jpg; base64 format data is converted to image
设计信息录入界面,完成人员基本信息的录入工作,
ShuffleNet v2网络结构复现(Pytorch版)
随机推荐
【虚幻引擎UE】UE5实现WEB和UE通讯思路
How many assertion methods are commonly used in JMeter?
虚拟机没有USB网卡选项怎么解决
高等代数_证明_两个矩阵乘积为0,则两个矩阵的秩之和小于等于n
分布式计算实验3 基于PRC的书籍信息管理系统
js - the first letter that appears twice
Detailed explanation of TCP protocol
一天搞定JDBC02:开启事务
Convert callback function to Flow
The national vocational skills contest competition of network security emergency response
LeetCode 135. 分发糖果
redis---分布式锁存在的问题及解决方案(Redisson)
字符流与字节流的区别
GBase 8c中怎么查询数据库配置参数,例如datestyle。使用什么函数或者语法呢?
使用requests post请求爬取申万一级行业指数行情
金仓数据库KingbaseES客户端编程接口指南-JDBC(7. JDBC事务处理)
关于常用状态码4XX提示错误
Distributed Computing Experiment 2 Thread Pool
安装GBase 8c数据库的时候,报错显示“Resource:gbase8c already in use”,这怎么处理呢?
安装GBase 8c数据库集群时,报错误码:80000306,显示Dcs cluster not healthy。怎么处理错误呢?