redis 的 maxmemory 和 output buffer 的关系?

2017-07-27 16:58:46 +08:00
 guyeuro

我看到有这么两段话:

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 里的空间?

1524 次点击
所在节点    问与答
5 条回复
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
2017-07-27 18:00:44 +08:00
@zts1993 没看很明白,假如某个机器内存是 64G,maxmemory 设置为 60G,这意思是 output buffer 最多能有 4G 还是说 output buffer 占用 maxmemory 那 60G 里的空间(从而挤占了键的空间)?
zts1993
2017-07-27 19:26:30 +08:00
@guyeuro #2 slave 的 output buffer 不挤占 maxmemory 设置。
guyeuro
2017-07-27 21:18:58 +08:00
@zts1993 那为何 output buffer 占用多的内存导致更多的键过期?
zts1993
2017-07-27 21:45:59 +08:00
@guyeuro #4 。第二个说的是如果计入,会造成什么样的后果。所以解决方案是把 obuf 移出去。

中文资料翻译不准确,可以参看这个 issue https://github.com/antirez/redis/issues/1687

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/378409

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX