Redis集群主备缓存区满了导致主备频繁倒换

问题现象

Redis 频繁进行主备倒换,通过查看主实例的日志:redis.log发现下面报错:

Client id=1317049445 addr=192.168.2.45:8004 fd=40 name= age=314 idle=0 flags=S db=0 sub=0
 psub=0 multi=-1 qbuf=0 qbuf-free=32568 obl=0 oll=4430 omem=761143439 events=rw cmd=psync 
scheduled to be closed ASAP for overcoming of output buffer limits

其中:psync scheduled to be closed ASAP for overcoming of output buffer limits 明显就是问题所在,那是什么问题呢。

解决思路

于是我在源码中搜索了scheduled to be closed ASAP for overcoming of output buffer limits(psync明显是一个命令,就不用在代码里面搜索了)。

于是,我找到了下面代码:

/* If the source client contains a partial response due to client output
     * buffer limits, propagate that to the dest rather than copy a partial
     * reply. We don't wanna run the risk of copying partial response in case
     * for some reason the output limits don't reach the same decision (maybe
     * they changed) */
    if (src->flags & CLIENT_CLOSE_ASAP) {
        sds client = catClientInfoString(sdsempty(),dst);
        freeClientAsync(dst);
        serverLog(LL_WARNING,"Client %s scheduled to be \
                closed ASAP for overcoming of output buffer limits.", client);
        sdsfree(client);
        return;
    }

单从代码来看,看不出啥,但是代码上面存在注释,我使用我那四级水平翻译了下,可以看出缓存区满了,于是可以想到可能主备同步的时候可能会限制缓存区大小,并且这个缓存区被占满了。

于是我又在redis.conf中找了缓冲区的相关配置,找到了下面是三个:

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

配置格式为:

client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>

具体含义:

  • class:我理解就是缓冲区的类型,目前Redis的缓冲区分为三个:

    • 普通客户端:normal
    • 主备同步:replica
    • 发布订阅:pubsub
  • hard limit: 缓冲区大小的硬性限制。当达到这个限制之后,连接就会断开。
  • soft limit: 缓冲去大小的软性限制。
  • soft seconds: 缓冲区大小达到了(超过)soft limit值的持续时间。

因此我们可以将client-output-buffer-limit replica 256mb 64mb 60作出简单调整,重启Redis服务之后解决这个问题。

# redis  原创 


标 题:《Redis集群主备缓存区满了导致主备频繁倒换
作 者:zeekling
提 示:转载请注明文章转载自个人博客:浪浪山旁那个村

评论

取消