国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Redis > 正文

淺談redis的maxmemory設置以及淘汰策略

2020-10-28 21:37:25
字體:
來源:轉載
供稿:網友

redis的maxmemory參數用于控制redis可使用的最大內存容量。如果超過maxmemory的值,就會動用淘汰策略來處理expaire字典中的鍵。

關于redis的淘汰策略:

Redis提供了下面幾種淘汰策略供用戶選擇,其中默認的策略為noeviction策略:

?   noeviction:當內存使用達到閾值的時候,所有引起申請內存的命令會報錯。

?   allkeys-lru:在主鍵空間中,優先移除最近未使用的key。

?   volatile-lru:在設置了過期時間的鍵空間中,優先移除最近未使用的key。

?   allkeys-random:在主鍵空間中,隨機移除某個key。

?   volatile-random:在設置了過期時間的鍵空間中,隨機移除某個key。

?   volatile-ttl:在設置了過期時間的鍵空間中,具有更早過期時間的key優先移除。

PS:

關于maxmemory的設置,如果redis的應用場景是作為db使用,那不要設置這個選項,因為db是不能容忍丟失數據的。

如果作為cache使用,則可以啟用這個選項(其實既然有淘汰策略,那就是cache了。。。)

但是在集群環境下(尤其是有多個slavers的情形),maxmeomory的值并不是實際redis使用的內存,這個選項值并沒有包括slaver的output buffer。

redis早期版本出過一個bug,在多個slaver的情形下,設置了maxmemory值,同時設定了淘汰策略,會造成master上的數據被漸漸擦除。

antirez先生給出了這個問題的原因:

The issue happens for the following reason: Redis reached the configured limit, so it tries to expire keys.Evicting keys turns into explicit DELs sent to slaves, since masters control the eviction of slaves for well known reasons.But this way if there are enough slaves, emitting the protocol in the output buffers will actually take more memory than the amount freed removing keys...So the key eviction process starts to enter into an infinite loop.Up to a given point the fact that there is a static buffer part in the output queue of every client (including slaves) mitigate this in certain conditions, but once Redis can't use the output buffer but must use the queue of objects the infinite loop is triggered. 

簡單說來,刪除過期鍵,需要產生del命令發送給slaver,如果slaver足夠多,output buffer將會占用足夠多的內存,導致更多的鍵過期,如此往復,陷入了無線循環。

解決方案有多種,比如output buffer可以不計入maxmemory。

因此,在3.0版本的配置說明中有了以下表述:

# WARNING: If you have slaves attached to an instance with maxmemory on,# the size of the output buffers needed to feed the slaves are subtracted# from the used memory count, so that network problems / resyncs will# not trigger a loop where keys are evicted, and in turn the output# buffer of slaves is full with DELs of keys evicted triggering the deletion# of more keys, and so forth until the database is completely emptied.## In short... if you have slaves attached it is suggested that you set a lower# limit for maxmemory so that there is some free RAM on the system for slave# output buffers (but this is not needed if the policy is 'noeviction').## maxmemory <bytes></bytes> 

由此可見,如果有slaver的情況下,建議適當調低maxmemory,給output buffer留出一定的可用空間是合理的。

以上這篇淺談redis的maxmemory設置以及淘汰策略就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 屏山县| 遂平县| 湟中县| 庆阳市| 云南省| 东海县| 遂平县| 大埔区| 修武县| 贵定县| 徐汇区| 尚义县| 玛沁县| 黄平县| 吉林市| 晋中市| 新野县| 怀柔区| 胶州市| 昂仁县| 巩义市| 雷波县| 故城县| 鄂托克前旗| 司法| 诸城市| 鄂州市| 南岸区| 武威市| 民丰县| 陕西省| 云南省| 项城市| 宁都县| 探索| 永康市| 杭州市| 澄城县| 兴国县| 崇左市| 军事|