好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 淺談redis的maxmemory設置以及淘汰策略

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

熱門標簽:西藏教育智能外呼系統價格 竹間科技AI電銷機器人 玄武湖地圖標注 小紅書怎么地圖標注店 地圖標注費用 百度商家地圖標注怎么做 地圖標注如何即時生效 最簡單的百度地圖標注 太原營銷外呼系統

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設置以及淘汰策略就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Redis中LRU淘汰策略的深入分析
  • 關于redis Key淘汰策略的實現方法
  • 淺談Redis緩存有哪些淘汰策略

標簽:澳門 揚州 廣東 景德鎮 林芝 香港 贛州 唐山

巨人網絡通訊聲明:本文標題《淺談redis的maxmemory設置以及淘汰策略》,本文關鍵詞  淺談,redis,的,maxmemory,設置,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《淺談redis的maxmemory設置以及淘汰策略》相關的同類信息!
  • 本頁收集關于淺談redis的maxmemory設置以及淘汰策略的相關信息資訊供網民參考!
  • 推薦文章