zoukankan      html  css  js  c++  java
  • 经验分享:防止Redis网络闪断进行主从全量同步

    防止Redis网络闪断进行全量同步

    当网络抖动时Redis 会发生主从全量同步,如果数据量大的话,加上传输时间,Reload时间会让业务长时间异常,可以从以下参数上进行调整,有效防止网络闪断带来的风险。

    1.repl-timeout

    redis里面的repl-timeout参数值太小也将会导致复制不成功.

    redis配置文件中对repl-timeout的参数解释如下:

    # The following option sets the replication timeout for:
    #
    # 1) Bulk transfer I/O during SYNC, from the point of view of slave.
    # 2) Master timeout from the point of view of slaves (data, pings).
    # 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).

    三种情况认为复制超时:

    1)slave角度,如果在repl-timeout时间内没有收到master SYNC传输的rdb snapshot数据,
    2)slave角度,在repl-timeout没有收到master发送的数据包或者ping。
    3)master角度,在repl-timeout时间没有收到REPCONF ACK确认信息。

    当redis检测到repl-timeout超时(默认值60s),将会关闭主从之间的连接,redis slave发起重新建立主从连接的请求。

    对于内存数据集比较大的系统,可以增大repl-timeout参数。

    2.slave ping period

    redis slave会定期从master发送ping命令,时间间隔repl-ping-slave-period指定。

    因而,设置参数时, repl-timeout > repl-ping-slave-period。

    # Slaves send PINGs to server in a predefined interval. The default value is 10 seconds.
    # repl-ping-slave-period 10

    # It is important to make sure that this value is greater than the values pecified for repl-ping-slave-period otherwise a timeout will be detected every time there is low traffic between the master and the slave.

    3.repl-backlog-size

    当主服务器进行命令传播的时候,maser不仅将所有的数据更新命令发送到所有slave的replication buffer,还会写入replication backlog。当断开的slave重新连接上master的时候,slave将会发送psync命令(包含复制的偏移量offset),请求partial resync。如果请求的offset不存在,那么执行全量的sync操作,相当于重新建立主从复制。

    为了避免网络不稳定造成的全量同步.

    修改参数如下:

    config set repl-timeout 240
    config set repl-backlog-size 524288000
  • 相关阅读:
    音视频-x624和H.264
    状态机解决复杂逻辑及使用
    任意程序上的蒙版画笔实现
    WPF-3D圆柱体透视
    WPF-3D-Z-buffering 导致的遮盖物体不渲染问题
    WPF3D立方体图形展开动画思路
    解决Prism 8.0 I添加InvokeCommandAction xaml报错问题
    Spark编程基础(Python版)
    前端开发工具fscapture
    修改element ui select选择器 样式
  • 原文地址:https://www.cnblogs.com/WIU1905/p/11802847.html
Copyright © 2011-2022 走看看