最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談redis的maxmemory設(shè)置以及淘汰策略

 更新時間:2017年03月27日 09:05:47   投稿:jingxian  
下面小編就為大家?guī)硪黄獪\談redis的maxmemory設(shè)置以及淘汰策略。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

關(guān)于redis的淘汰策略:

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

·   noeviction:當(dāng)內(nèi)存使用達(dá)到閾值的時候,所有引起申請內(nèi)存的命令會報錯。

·   allkeys-lru:在主鍵空間中,優(yōu)先移除最近未使用的key。

·   volatile-lru:在設(shè)置了過期時間的鍵空間中,優(yōu)先移除最近未使用的key。

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

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

·   volatile-ttl:在設(shè)置了過期時間的鍵空間中,具有更早過期時間的key優(yōu)先移除。

PS:

關(guān)于maxmemory的設(shè)置,如果redis的應(yīng)用場景是作為db使用,那不要設(shè)置這個選項,因為db是不能容忍丟失數(shù)據(jù)的。

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

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

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

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. 

簡單說來,刪除過期鍵,需要產(chǎn)生del命令發(fā)送給slaver,如果slaver足夠多,output buffer將會占用足夠多的內(nèi)存,導(dǎo)致更多的鍵過期,如此往復(fù),陷入了無線循環(huán)。

解決方案有多種,比如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的情況下,建議適當(dāng)調(diào)低maxmemory,給output buffer留出一定的可用空間是合理的。

以上這篇淺談redis的maxmemory設(shè)置以及淘汰策略就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Redis實現(xiàn)UV統(tǒng)計的示例代碼

    Redis實現(xiàn)UV統(tǒng)計的示例代碼

    本文主要介紹了Redis實現(xiàn)UV統(tǒng)計的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • Redis實現(xiàn)限量優(yōu)惠券的秒殺功能

    Redis實現(xiàn)限量優(yōu)惠券的秒殺功能

    文章詳細(xì)分析了避免超賣問題的方法,包括確保一人一單的業(yè)務(wù)邏輯,并提供了代碼實現(xiàn)步驟和代碼示例,感興趣的朋友跟隨小編一起看看吧
    2024-12-12
  • redis反序列化報錯原因分析以及解決方案

    redis反序列化報錯原因分析以及解決方案

    這篇文章主要介紹了redis反序列化報錯原因分析以及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • redis不能訪問本機真實ip地址的解決方案

    redis不能訪問本機真實ip地址的解決方案

    這篇文章主要介紹了redis不能訪問本機真實ip地址的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • redis緩存一致性延時雙刪代碼實現(xiàn)方式

    redis緩存一致性延時雙刪代碼實現(xiàn)方式

    這篇文章主要介紹了redis緩存一致性延時雙刪代碼實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Redis高可用的三種實現(xiàn)方式

    Redis高可用的三種實現(xiàn)方式

    在實際生產(chǎn)環(huán)境中為保證Redis的服務(wù)連續(xù)性和可靠性,需要設(shè)計一個高可用架構(gòu),本文就來介紹一下Redis高可用的三種實現(xiàn)方式,主要包括主從復(fù)制模式,Redis Sentinel模式和Redis Cluster模式,感興趣的可以了解一下
    2023-12-12
  • 關(guān)于Redis網(wǎng)絡(luò)模型的源碼詳析

    關(guān)于Redis網(wǎng)絡(luò)模型的源碼詳析

    這篇文章主要給大家介紹了關(guān)于Redis網(wǎng)絡(luò)模型的源碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用Redis具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Redis 出現(xiàn)錯誤1067的解決辦法

    Redis 出現(xiàn)錯誤1067的解決辦法

    這篇文章主要介紹了Redis 出現(xiàn)錯誤1067的解決辦法的相關(guān)資料,Redis 錯誤1067:進程意外終止,Redis不能啟動,Redis啟動不了,需要的朋友可以參考下
    2017-07-07
  • Redis緩存異常常用解決方案總結(jié)

    Redis緩存異常常用解決方案總結(jié)

    Redis緩存異常問題分別是緩存雪崩,緩存預(yù)熱,緩存穿透,緩存降級,緩存擊穿,本文主要介紹了Redis緩存異常常用解決方案總結(jié),具有一定的參考價值,感興趣的可以了解一下
    2023-12-12
  • RedisDesktopManager?連接redis的方法

    RedisDesktopManager?連接redis的方法

    這篇文章主要介紹了RedisDesktopManager?連接redis,需要的朋友可以參考下
    2023-08-08

最新評論

陵川县| 鄄城县| 丰城市| 台东县| 宁阳县| 新泰市| 岳阳县| 鄱阳县| 平舆县| 明光市| 阿尔山市| 调兵山市| 自治县| 谢通门县| 杂多县| 武鸣县| 华宁县| 长乐市| 鸡泽县| 南召县| 宁都县| 迁安市| 京山县| 北川| 荣昌县| 昭平县| 桦川县| 拉孜县| 盐边县| 正蓝旗| 保康县| 南部县| 乌鲁木齐市| 东港市| 秭归县| 天峻县| 伊宁县| 拜泉县| 临洮县| 黄浦区| 永春县|