当前位置:网站首页>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
边栏推荐
- 如何利用 RPA 实现自动化获客?
- How to use RPA to achieve automatic customer acquisition?
- Responsive dream weaving template outdoor camping website
- 聊聊接口性能优化的11个小技巧
- Data security and privacy computing summit - development and application of security intersection in privacy Computing: Learning
- XSS靶场(二)xss.haozi
- Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM
- Kubesphere multi node installation
- VR safety training of mine mining virtual reality improves employees' vigilance and protection awareness
- 响应式织梦模板家装建材类网站
猜你喜欢

结合Retrofit 改造OKHttp 缓存

ES6 detailed quick start!

如果时间不够,无法进行充分的测试怎么办?

3d智能工厂工艺流转可视化交互展示应用优点

NPM install reports an error: eperm: operation not permitted, rename

如何把thinkphp5的项目迁移到阿里云函数计算来应对流量洪峰?

矿山开采虚拟现实vr安全培训提升员工警惕性和防护意识
![[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

The outsourcing company "mixed" for two years, and I only did five things seriously. Now I get byte offer smoothly.

Explain the four asynchronous solutions of JS in detail: callback function, promise, generator, async/await
随机推荐
WebView attack
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
Code implementation - the greatest common factor of polynomials (linear algebra)
MySQL和Redis的双写一致性
无线振弦采集系统工作流程
The first of the five tips for using browsers efficiently is the most practical
HTTP断点续传以及缓存问题
Experiment 2: Arduino's tricolor lamp experiment
Meeting notice of meeting OA
Responsive dream weaving template hotel room website
How to quickly design a set of cross end components that support rendering rich text content
物联网组件
Responsive dream weaving template home decoration building materials website
MySQL basic operation and comprehensive instance project based on MySQL basic operation
Interprocess communication - detailed explanation of the pipeline (explanation of graphic cases)
virsh console连接失败问题
详解异步任务:任务的状态及生命周期管理
VR safety training of mine mining virtual reality improves employees' vigilance and protection awareness
6年测试经验,教大家测试~如何把控项目
Explanation of engineering economics terms