当前位置:网站首页>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
边栏推荐
- 聊聊接口性能优化的11个小技巧
- Three implementation methods of Servlet
- Data security and privacy computing summit - development and application of security intersection in privacy Computing: Learning
- 工程经济学名词解释
- 线上3d数字展厅制作方案及优点
- 响应式织梦模板装修设计类网站
- 结合Retrofit 改造OKHttp 缓存
- 密码安全如何保障?安全浏览器如何管理密码?
- 数据安全与隐私计算峰会-安全求交集在隐私计算中的发展和应用:学习
- Talk about 11 tips for interface performance optimization
猜你喜欢

快速掌握Nodejs安装以及入门

I want to talk about high concurrency.
![[RT learning note 1] RT thread peripheral routine - control LED light flashing](/img/70/2c8cebd98948b5c92625c1a5423d97.png)
[RT learning note 1] RT thread peripheral routine - control LED light flashing

Exploration and practice of network security vulnerability management

How to quickly design a set of cross end components that support rendering rich text content

Day 14: continued day 13 label related knowledge

QT qstackedwidget multi interface switching

Prometheus + AlertManager 消息预警

ES6 detailed quick start!

ES6事件绑定(v-on用法)
随机推荐
On Multithreading
响应式织梦模板家装装饰类网站
会议OA之会议通知
time_wait和close_wait产生原因
Kbxxxxx is not necessarily a patch, but also a description of a solution to a problem
Code implementation - the greatest common factor of polynomials (linear algebra)
代码实现 —— 多项式的最大公因式(线性代数)
WebView attack
Workflow of wireless vibrating wire acquisition system
virsh console连接失败问题
聊聊 Feign 的实现原理
Excel uses countif statistics
Experiment 2: Arduino's tricolor lamp experiment
Servlet三种实现方式
我被这个浏览了 746000 次的问题惊住了
Derivation of Euler angle differential equation
6年测试经验,教大家测试~如何把控项目
Keil5 open the engineering prompt not found device solution
Understanding service governance in distributed development
“两个披萨”团队的分支管理实践