当前位置:网站首页>Redis deletion policy and eviction algorithm
Redis deletion policy and eviction algorithm
2022-06-29 13:13:00 【Wind chaser 0x8ffd98a8】
This article has participated in 「 New people's creation ceremony 」 Activities , Start the road of nuggets creation together .
Redis Run in memory , The data is also stored in memory . Limited memory and unlimited data , Generally, the expiration time is added to the primary key , Prevent data from filling the memory , You need to use the deletion strategy and the eviction algorithm .
Deletion policy
Expired data : Set the data of validity period , Expiry date ,Redis Not deleted immediately . Data deletion strategy is to process expired data , Control is expires Location .
There are three types of deletion policies , They are scheduled deletion 、 Lazy deletion and regular deletion . Balance memory and performance .
Delete regularly
Create a timer , When key Set expiration time , And when time arrives , There is a timer task to immediately delete the key . advantage : To save memory , Expire delete , Quickly free up unnecessary memory . shortcoming :CPU High pressure , No matter what CPU What is the load , All occupied CPU Delete operation , It will affect Redis Server response time and instruction throughput . summary : Trade processor performance for memory space .
Lazy deletion
Data arrival expiration time , Don't deal with it , Delete... The next time you access the data . If not expired , Return the data ; Found expired , Delete , Return does not exist . advantage : save CPU performance , Delete when you find that you have to delete . shortcoming : High memory pressure , Data that has occupied memory for a long time . summary : Trade memory space for processor performance .
Delete periodically
Redis When starting server initialization , Reading configuration server.hz Value , The default is 10. For each library expires Space ,expires[*]( Each library has this interval ) Conduct a round of inspection , Every time you execute 250ms/server.hz Time , To perform a second server.hz Time .
For each expires[*] When testing , Random selection W individual key testing ,W Value = ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP Property value .
If key Overtime , Delete key. If you delete in a round key The number is larger than W * 25%, Cycle the process . If you delete in a round key < W * 25%, Check the next exipires[*],0-15 loop .
Parameters current_db Used to record The method Which one to enter exipires[*] perform . Periodic polling Redis Time sensitive data in the library , Take the strategy of random selection , Use the proportion of expired data to control the frequency of deletion . summary : Periodically spot check storage space .
Delete strategy comparison
| Deletion policy | Memory footprint | CPU Resource utilization | The central idea |
|---|---|---|---|
| Delete regularly | To save memory , No occupation | Regardless of the time period CPU resources , High frequency | Performance for space |
| Lazy deletion | Heavy memory usage | Delayed execution ,CPUU High utilization | Space exchange performance |
| Delete periodically | Memory is cleaned up randomly on a regular basis | Spend... Of arc top per second CPU Resources maintain memory | Random sampling , Focus on spot check |
The eviction algorithm
When the data enters Redis when , If the memory does not meet the minimum storage requirements for adding data ,Redis To temporarily delete some data and clean up the storage space for the current instruction . The strategy for cleaning up data becomes the eviction algorithm .
Eviction algorithm related configuration :
maxmemory Maximum available memory , Default 0, unlimited . maxmemory-samples Select the number of data to be deleted each time . maxmemory-policy Configure the eviction algorithm .
After reaching the maximum memory , The strategy of expelling selected data , The selected data will not be scanned in the whole database .
The eviction algorithm :
Detect volatile data ( Data sets that may be out of date server.db[i].expires)
- volatile-lru Recently, the least used data has been eliminated
- volatile-lfu The data that has been used least recently is eliminated
- volatile-ttl Obsolete data should be eliminated
- volatile-random Choose any data to eliminate
Check the whole database data ( All data sets server.db[i].dict)
- allkeys-lru
- allkeys-lfu
- allkeys-random
Give up data
no-enviction: Exclusion data , May trigger OOM
边栏推荐
- C#通過中序遍曆對二叉樹進行線索化
- File contained log poisoning (user agent)
- 如何计算win/tai/loss in paired t-test
- Application Service Vulnerability scanning and exploitation of network security skills competition in secondary vocational schools (SSH private key disclosure)
- C#通过线索二叉树进行中序遍历输出
- Recurrence of recommended models (IV): multi task models esmm and MMOE
- STK_GLTF模型
- Simple introduction to matlab
- 代码整洁之道学习笔记
- Problem solving: modulenotfounderror: no module named 'pip‘
猜你喜欢

Cvpr2022 𞓜 loss problem in weakly supervised multi label classification

The role of each part of Neural Network & thoroughly understand neural network

Matlab简单入门

Tutorial on building pytoch model from zero (V) writing training process -- some basic configurations

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file

STK_ Gltf model

CVPR2022 | 通过目标感知Transformer进行知识蒸馏

神经网络各个部分的作用 & 彻底理解神经网络

安装typescript环境并开启VSCode自动监视编译ts文件为js文件

Hystrix circuit breaker
随机推荐
C # implements the operations of sequence table definition, insertion, deletion and search
Lm07 - detailed discussion on cross section strategy of futures
Equidistant segmentation of surface rivers in ArcGIS [gradient coloring, pollutant diffusion]
Nacos startup error
C#实现堆栈结构的定义、入栈、出栈
Recurrence of recommended models (IV): multi task models esmm and MMOE
如何统计项目代码(比如微信小程序等等)
项目管理复习题
C#实现二叉排序树定义、插入、构造
The role of each part of Neural Network & thoroughly understand neural network
C#实现二叉树的先序遍历、中序遍历、后序遍历
leetcode 第 299场周赛
2022.6.28-----leetcode. three hundred and twenty-four
C#实现队列结构定义、入队、出队操作
Install the terrain ovirt plug-in to provide automated management for ovirt
CVPR2022 | A ConvNet for the 2020s & 如何设计神经网络总结
Precautions for Beifu controller connecting Panasonic EtherCAT servo
商品搜索引擎—推荐系统设计
RT thread memory management
面试突击61:说一下MySQL事务隔离级别?