diff --git a/中间件/redis/redis.md b/中间件/redis/redis.md index 3fc2376..764661d 100644 --- a/中间件/redis/redis.md +++ b/中间件/redis/redis.md @@ -226,6 +226,8 @@ - [CLUSTER SLOTS](#cluster-slots) - [Multi-keys operations](#multi-keys-operations) - [Scaling reads using replica nodes](#scaling-reads-using-replica-nodes) + - [Fault Tolerance](#fault-tolerance) + - [Heartbeat and gossip message](#heartbeat-and-gossip-message) # redis @@ -3598,3 +3600,19 @@ MSET {user:1000}.name Angela {user:1000}.surname White 当发生该场景时,replica会向client发送重定向,而client则应该更新其`hash slot map`。 +### Fault Tolerance +#### Heartbeat and gossip message +redis cluster nodes会持续的交换ping和pong packets。ping packet和pong packet的结构相同,都包含configuration information。ping packet和pong packet的唯一区别为message type field。 + +> `ping packets和pong packets被统称为heartbeat packets`。 + +通常,在node发送ping packets时,将会导致receiver返回一个pong packet。但是,`node也能够在未接收到ping packets的情况下发送pong packets`,用于向其他节点发送其自身的配置信息。在对`new configuration`进行广播时,该机制十分有用。 + +通常,每过几秒,node都会随机ping一系列其他节点。故而,不管集群的规模如何,每个节点发送的ping packets都是恒定的。(node并不会因为集群规模扩大,向集群所有其他节点发送ping packets导致ping packets的总数上升)。 + +但是,every node makes sure to ping every other node that hasn't sent a ping or received a pong for longer than `NODE_TIME / 2` time。在`NODE_TIME`到期之前,node也会对其他节点尝试重新连接,确保其他节点不会因为当前tcp连接的问题而将其他节点判定为不可访问。 + +当`NODE_TIME`设置的较小时,消息交换会更加频繁,且当节点数量较多时,信息交换的数量可能会相当庞大。因为没过`NODE_TIME / 2`时间,每个节点都要ping所有其他节点,以获取最新的消息。 + +例如,在一个规模为100的集群中,如果将`node timeout`设置为60s,每个节点在每30s都会尝试发送99个ping,故而每个节点每秒钟平均发送`3.3`个ping,整个集群每秒钟平均发送`330`个ping。 +