当前位置:网站首页>Redis (IV) - delete policy
Redis (IV) - delete policy
2022-06-30 18:02:00 【Zhaoliwen is a pig】
Redis( Four )—— Deletion policy
List of articles
1、 Data deletion strategy
- Delete regularly
- Lazy deletion
- Delete periodically
The storage structure of timeliness data
- Redis Data in , stay expire Is stored in it as a hash . Its value Is the address of the data in memory ,filed Is the corresponding life cycle
The goal of the data deletion strategy
In memory footprint and CPU Find a way between occupation Balance , Taking care of one thing and losing the other will result in the whole redis Performance degradation , Even cause server downtime or memory leakage
2、 Three deletion strategies
Delete regularly
- Create a timer , When key Set an expiration time , And when the expiration time arrives , By timer task Execute now Delete key
- 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 )
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 ( Change space for time )
Delete periodically
- Periodic polling redis Time sensitive data in the library , use The strategy of random extraction , Use the proportion of expired data to control the frequency of deletion
- 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 ( Random sampling , Focus on spot check )
3、 The eviction algorithm
When new data enters redis when , What if there's not enough memory ?
- 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 .
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
Related configurations that affect data eviction
LRU: The longest unused data
LFU: The least used data in a period of time
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
边栏推荐
- Building a basic buildreoot file system
- 【机器学习】K-means聚类分析
- Thinking on large file processing (upload, download)
- K-line diagram interpretation and practical application skills (see position entry)
- New power of data analysis -- the first open source integrated real-time HTAP database in China was released by stonedb
- Design and principle of tubes responsive data system
- Exch: repair the missing system mailbox
- Development details of NFT casting trading platform
- .NET ORM框架HiSql实战-第一章-集成HiSql
- New skill: accelerate node through code cache JS startup
猜你喜欢
送受伤婴儿紧急就医,滴滴司机连闯五个红灯
自旋锁探秘
广电5G正式启航,黄金频段将如何应用引关注
Solution: STM32 failed to parse data using cjson
Implementation of graduation project management system based on SSM
每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路
leetcode:1042. Do not plant flowers adjacent to each other [randomly fill in qualified + no contradiction will be formed behind + set.pop]
2022上半年盘点:20+主流数据库重大更新及技术要点汇总
Hyper-V: enable SR-IOV in virtual network
Splitting.js文本标题缓慢加载js特效
随机推荐
Exch:exchange server 2013 is about to end support
Shortcut keys for the rainbow brackets plug-in
广电5G正式启航,黄金频段将如何应用引关注
自旋锁探秘
Parker proportional overflow valve rs10r35s4sn1jw
Exch:Exchange Server 2013 即将终止支持
Network: principle and practice of server network card group technology
Parker variable displacement piston pump pv092r1k1t1nmmc
Vue3 reactive database
splitting. JS password display hidden JS effect
Taishan Office Technology Lecture: how to align and draw words of different sizes on the same line
Booking UI effect implemented by svg
应届生毕业之后先就业还是先择业?
零基础也能做Apple大片!这款免费工具帮你渲染、做特效、丝滑展示
分布式机器学习:模型平均MA与弹性平均EASGD(PySpark)
Daily question brushing record (IX)
基于SSH的通讯网络电子计费系统
生成对抗网络,从DCGAN到StyleGAN、pixel2pixel,人脸生成和图像翻译。
MSF后渗透总结
Building a basic buildreoot file system