当前位置:网站首页>Three expiration strategies
Three expiration strategies
2022-07-29 02:35:00 【Meme_ xp】
1. Delete regularly
meaning : Set up key At the same time , For the sake of key Create a timer , Let the timer be in key When the expiration time of , Yes key To delete
advantage :
Make sure the memory is released as soon as possible
shortcoming :
1. If overdue key quite a lot , Delete these key It will take up a lot of CPU Time , stay CPU When time is tight ,CPU You can't spend all your time doing something important , And take the time to delete these key
2. Timer creation time consuming , If you set the expiration time for each key Create a timer ( There will be a lot of timers ), Serious performance impact
3. Nobody uses
2. Lazy deletion
meaning :
key Do not delete when expired , Get... From the database every time key Check if it's overdue , If overdue , Delete , return null.
advantage :
The delete operation only occurs when fetching from the database key When it happens , And only delete the current key, So for CPU Time is less , And the deletion at this time has reached the point where we have to do something ( If it is not deleted at this time , We will get the expired key 了 )
shortcoming :
If a large number of key After exceeding the timeout period , For a long time , Have not been acquired , Then there may be a memory leak ( Useless garbage takes up a lot of memory )
Delete periodically
meaning :
Delete every once in a while ( stay redis.conf Profile Settings hz,1s Refresh frequency ) Be overdue key operation
advantage :
1. By limiting the duration and frequency of delete operations , To reduce the number of delete operations CPU The occupation of time – Handle " Delete regularly " The shortcomings of
2. Periodically delete expired key– Handle " Lazy deletion " The shortcomings of
shortcoming
1. In terms of memory friendliness , Not as good as " Delete regularly "
2. stay CPU Time friendly , Not as good as " Lazy deletion "
difficulty
Reasonably set the execution time of delete operation ( How long does each deletion take ) And execution frequency ( How often do I delete )( This depends on the operation of the server )
After reading the above three strategies, we can draw the following conclusions :
1. Regular deletion and regular deletion are active deletion :Redis Will regularly take the initiative to eliminate a number of past key
2. Lazy delete is passive delete : It's only tested when it's used key Is it overdue , Delete after expiration
3. Inertia deleted as redis Server built-in strategy
Regular deletion can be done through :
First of all 、 To configure redis.conf Of hz Options , The default is 10 ( namely 1 Seconds to perform 10 Time ,100ms once , The higher the value, the faster the refresh rate , most Redis The greater the performance loss )
second 、 To configure redis.conf Of maxmemory Maximum , When used memory exceeds maxmemory When limited , Will trigger the active clean-up strategy
边栏推荐
- Derivation of Euler angle differential equation
- When I look at the source code, what am I thinking?
- redis为什么快,消息队列,单线程
- Prometheus + alertmanager message alert
- 6 years of testing experience, teaching you how to test ~ how to control the project
- What should I do if excel opens a CSV file containing Chinese characters and there is garbled code?
- 3D模型格式全解|含RVT、3DS、DWG、FBX、IFC、OSGB、OBJ等70余种
- Summary of knowledge points of Engineering Economics
- Responsive Zhimeng template decoration design website
- 多边形点测试
猜你喜欢

Never pass a request to an asynchronous thread. There is a hole

What happens if you have to use ArrayList in multithreading?

Servlet三种实现方式

6年测试经验,教大家测试~如何把控项目

详解异步任务:任务的状态及生命周期管理

【质量】代码质量评价标准

如果非要在多线程中使用 ArrayList 会发生什么?
[email protected] The localization rate reaches 100%"/>Quanzhi t3/a40i industrial core board, 4-core [email protected] The localization rate reaches 100%

Prometheus + alertmanager message alert

发布融资需求1.29亿元,大科城项目路演持续浇灌科创“好苗子”
随机推荐
What if there is not enough time for adequate testing?
主从复制及其原理
ES6详解 快速上手!
redis为什么快,消息队列,单线程
Responsive Zhimeng template decoration design website
发布融资需求1.29亿元,大科城项目路演持续浇灌科创“好苗子”
Thermistor temperature calculation formula program
7/28 Gauss elimination to solve linear equations + Gauss elimination to solve XOR linear equations + find the combination number II
如何把thinkphp5的项目迁移到阿里云函数计算来应对流量洪峰?
XSS靶场(二)xss.haozi
C语言实现三子棋游戏
Rust 列表(Vec)复制
Waiting queue wait_ queue
Transform okhttp cache with retrofit
The financing demand of 129 million yuan was released, and the roadshow of the Dake city project continued to irrigate the "good seedlings" of scientific innovation
Brief answer of Engineering Economics
线上3d数字展厅制作方案及优点
Even PostgreSQL problem: expected authentication request from server, but received V
Practice and experience of security compliance in instant messaging scenarios
高效使用浏览器的5个小技巧,第1个技巧最实用