V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
guyeuro
V2EX  ›  问与答

redis 的 maxmemory 和 output buffer 的关系?

  •  
  •   guyeuro · 2017-07-27 16:58:46 +08:00 · 1510 次点击
    这是一个创建于 2465 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我看到有这么两段话:

    1 maxmemory 的值并不是实际 redis 使用的内存,这个选项值并没有包括 slaver 的 output buffer。

    2 删除过期键,需要产生 del 命令发送给 slaver,如果 slaver 足够多,output buffer 将会占用足够多的内存,导致更多的键过期,如此往复,陷入了无线循环。解决方案有多种,比如 output buffer 可以不计入 maxmemory。

    一个说“ maxmemory 的值没有包括 slaver 的 output buffer ”, 一个说“ output buffer 可以不计入 maxmemory。”

    我没看懂这两者之间究竟什么关系?

    假如某个机器内存是 64G,maxmemory 设置为 60G,这意思是 output buffer 最多能有 4G 还是说 output buffer 占用 maxmemory 那 60G 里的空间?

    5 条回复    2017-07-27 21:45:59 +08:00
    zts1993
        1
    zts1993  
       2017-07-27 17:22:04 +08:00
    output buffer 好像计入内存使用的统计的(统计是根据 malloc 的总大小来的)

    但是 在 freeMemoryIfNeeded 时候 是会扣除 slave 的 output buffer, 原因如 2 (这段话是翻译的,antirez 说的吧)

    在 freeMemoryIfNeeded 中
    size_t overhead = freeMemoryGetNotCountedMemory();
    mem_used = (mem_used > overhead) ? mem_used-overhead : 0;
    版本 4.0.0 有兴趣可以看下
    这里 检查 mem_used 和 maxmemory 大小的时候 , 扣掉了 overhead (里面就是 slave 的 output buffer ) ,这个动作也就是 你说的第 1 点

    另外一个和 replication 有关的参数 replbacklog size 是计入的~
    guyeuro
        2
    guyeuro  
    OP
       2017-07-27 18:00:44 +08:00
    @zts1993 没看很明白,假如某个机器内存是 64G,maxmemory 设置为 60G,这意思是 output buffer 最多能有 4G 还是说 output buffer 占用 maxmemory 那 60G 里的空间(从而挤占了键的空间)?
    zts1993
        3
    zts1993  
       2017-07-27 19:26:30 +08:00
    @guyeuro #2 slave 的 output buffer 不挤占 maxmemory 设置。
    guyeuro
        4
    guyeuro  
    OP
       2017-07-27 21:18:58 +08:00
    @zts1993 那为何 output buffer 占用多的内存导致更多的键过期?
    zts1993
        5
    zts1993  
       2017-07-27 21:45:59 +08:00
    @guyeuro #4 。第二个说的是如果计入,会造成什么样的后果。所以解决方案是把 obuf 移出去。

    中文资料翻译不准确,可以参看这个 issue https://github.com/antirez/redis/issues/1687
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1561 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:24 · PVG 01:24 · LAX 10:24 · JFK 13:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.