当前位置:网站首页>Redis data deletion policy in 2022
Redis data deletion policy in 2022
2022-06-12 14:07:00 【Xiao Zhong wants to learn!!!】
Redis Data deletion strategy
Redis Data features in
Redis It's a memory level database , All data is stored in memory , The data in memory can be accessed by TTL Command gets its state
- XX : Time sensitive data
- -1 : Permanent data
- -2: Expired data or deleted data or undeleted data
The storage structure of timeliness data
Setting time key, adopt hash To store key The address and the time of survival , When you need to delete data later, you can delete it according to hash You can delete the data when you find the address in the field of
1、 Delete regularly
Create a timer , When key Set an expiration time , And when the expiration time arrives , Delete the key immediately by the timer task
usage :
advantage : To save memory , Then delete , Free up unnecessary memory quickly
shortcoming :CPU Under great pressure , No matter what CPU How high is the load at this time , All occupied CPU, It will affect redis Server response time and instruction throughput
summary : Trade processor performance for storage ( Time for space )
2、 Lazy deletion
Data arrival expiration time , Don't deal with it . 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 : There's a lot of memory pressure , Data that has occupied memory for a long time
summary : Swapping memory for processor performance ( Time for space )
There's one in here
expireIfNeeded()It is used to detect whether it is expired
3、 Delete periodically
Periodic polling redis Time sensitive data in the library , Using random sampling strategy , Use the proportion of expired data to control the frequency of deletion
- Redis When starting server initialization , Reading configuration server.hz Value , The default is 10
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-npWPEbuQ-1654997799056)(images/image-20220612072030264.png)]](/img/05/1d27f811bb0bad0a811e08524c38cd.png)
Every second server.hz Time serverCron()——》databasesCron()——》activeExpireCycle()
**activeExpireCycle()** For each expires[*] Test them one by one , Every time you execute 250ms/server.hz
To someone expires[] When testing , Random selection W individual key Detect a expires[] When testing , Random selection W individual key testing
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-M8IG3IVl-1654997799057)(images/image-20220612072254894.png)]](/img/f3/1f6e46047d5def6107a6bf4604afcc.png)
- If key Overtime , Delete key
- If you delete in a round key The number of >W*25%, Cycle the process
- If you delete in a round key The number of ≤W25%, Check the next expires[],0-15 loop
- W Value =ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP Property value
Parameters current_db Used to record activeExpireCycle() Which one to enter expires[*] perform
If **activeExpireCycle()** Execution time expired , Next time from current_db Keep going down
characteristic 1:CPU Performance occupancy settings have peaks , The detection frequency can be customized
characteristic 2: Memory pressure is not great , Cold data that has occupied memory for a long time will be continuously cleaned up
summary : Periodically spot check storage space expireIfNeeded()( Random sampling , Focus on spot check )
4、 The eviction algorithm
Redis Using memory to store data , Before executing every command , Would call **freeMemoryIfNeeded()** Check if there is enough memory . If the memory does not meet the minimum storage requirements for newly added data ,redis To temporarily delete some data and clean up the storage space for the current instruction . The strategy for cleaning up data is called the eviction algorithm
Be careful : The process of evicting data is not 100% Can clean up enough available memory space , If not, repeat . After trying all the data , If the requirement of memory cleaning cannot be met , An error message will appear .
(error) OOM command not allowed when used memory >'maxmemory'
Related configurations that affect data eviction
Maximum available memory
maxmemory
The proportion of physical memory occupied , The default value is 0, Means unrestricted . In the production environment, set according to the demand , Usually set at 50% above .
Select the number of data to be deleted each time
maxmemory-samples
Data selection does not scan the entire database , Leading to serious performance consumption , Reduce read and write performance . Therefore, the method of randomly obtaining data is adopted as the data to be detected and deleted
Deletion policy
maxmemory-policy
After reaching the maximum memory , The strategy of deleting the selected data
Detect volatile data ( Data sets that may be out of date server.db[i].expires )
- volatile-lru: Select the least recently used data
- volatile-lfu: Select the data that has been used least recently
- volatile-ttl: Select the data that will be out of date
- volatile-random: Choose any data to eliminate
Check the whole database data ( All data sets server.db[i].dict )
- allkeys-lru: Select the least recently used data
- allkeys-lfu: Select the data that has been used least recently
- allkeys-random: Choose any data to eliminate
Give up data
- no-enviction( deportation ): Exclusion data (redis4.0 Default policy in ), Error will be raised OOM(Out Of Memory)
maxmemory-policy volatile-lru
Data eviction policy configuration basis
Use INFO Command output monitoring information , The query cache hit and miss The number of times , Tune according to business needs Redis To configure
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-wmubQyo8-1654997799058)(images/image-20220612080550544.png)]](/img/0b/d8294cc64584ecbfcc1e72e852ab9a.png)
边栏推荐
- Knowledge of wireless card driver
- [wustctf2020] selfie score query -1
- Programmer interview golden classic good question / interview question 01.05 Edit once
- How test engineers transform test and open
- Simple implementation of gpuimage chain texture
- Details of bypassing safeseh mechanism by using modules that do not enable safeseh
- SystemC simulation scheduling mechanism
- Data type conversion and conditional control statements
- Des File Encryptor based on MFC framework
- Redis核心配置和高级数据类型
猜你喜欢

TestEngine with ID ‘junit-vintage‘ failed to discover tests

Behind the unsealing of Shanghai, this group of developers "cloud gathering" built an AI anti epidemic robot

如何使用android studio制作一个阿里云物联网APP
![[WUSTCTF2020]颜值成绩查询-1](/img/90/e4c2882357e0a1c6a80f778887e3f5.png)
[WUSTCTF2020]颜值成绩查询-1
Ffmpeg Learning Guide

MySQL 查询 limit 1000,10 和 limit 10 速度一样快吗? 深度分页如何破解

618 entered the second half of the period, apple occupied the high-end market, and the domestic mobile phones finally undercut the price competition

Implementation and debug of process hiding under x64

【视频课】android studio物联网APP设计制作全套教程--国庆期间全掌握

What is automatic bidding? What are its advantages?
随机推荐
【SemiDrive源码分析】【X9芯片启动流程】26 - R5 SafetyOS 之 LK_INIT_LEVEL_TARGET 阶段代码流程分析(TP Drvier、Audio Server初始化)
TestEngine with ID ‘junit-vintage‘ failed to discover tests
OAuth2学习中的一些高频问题的QA
lua 常用内置函数
阿里云开发板HaaS510报送设备属性
atomic and exclusive operation
Alibaba cloud development board haas510 submission device attributes
Reverse analysis from x86 to x64tips
QA of some high frequency problems in oauth2 learning
[semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX
Formal analysis of Woo Lam protocol with scyther tool
Transmission and response of events and use cases
动态搜索广告智能查找匹配关键字
如果要打造品牌知名度,可以选择什么出价策略?
What is the default gateway
3. Process concealment under the ring ----- continuous concealment and new opening prevention
969. pancake sorting
CSDN blog points rule
AVFoundation
测试工程师如何转型测开