为什么hash槽的大小为16384?

这是作者给出的原话:

 

Normal heartbeat packets carry the full configuration of a node, that can be replaced in an idempotent way with the old in order to update an old config.

正常的心跳包携带节点的完整配置,可以用幂等方式替换旧节点,以便更新旧配置。

 

This means they contain the slots configuration for a node, in raw form, that uses 2k of space with16k slots, but would use a prohibitive 8k of space using 65k slots.

这意味着它们包含一个节点的插槽配置,在原始形式中,该节点使用2k的空间和16k的插槽,但使用65k的插槽将使用令人望而却步的8k空间。

 

At the same time it is unlikely that Redis Cluster would scale to more than 1000 mater nodes because of other design tradeoffs.

与此同时,Redis集群不太可能因为其他设计权衡而扩展到超过1000个主节点。

 

So 16k was in the right range to ensure enough slots per master with a max of 1000 maters, but a small enough number to propagate the slot configuration as a raw bitmap easily.

因此,16k是在合适的范围内,以确保每个主服务器有足够的插槽,最多1000个maters,但这个数字足够小,可以很容易地将插槽配置作为原始位图传播。

 

Note that in small clusters the bitmap would be hard to compress because when N is small the bitmap would have slots/N bits set that is a large percentage of bits set.

注意,在小型集群中,位图很难压缩,因为当N很小时,位图将设置槽/N位,这是设置的位的很大比例。

 

Redis集群计算Key的算法:

https://segmentfault.com/a/1190000018094567?utm_source=tag-newest

Key=CRC16(Key)%16384

CRC16(Key)算法有2^16=65536个值,范围0-65535bit之间

也就是根据算法来说:

Key=CRC16(Key)%16384 =>Key=(0-65536)%16384 key的范围0-16383

为什么Key=CRC16(Key)%16384而不是Key=CRC16(Key)%65536?

Redis之间的通讯采用的Gossip协议,Redis之间的ping/pong非常的频繁,所以我们在停到集群中的一个节点立马能看到整个集群的不可用。

Gossip协议:https://zhuanlan.zhihu.com/p/41228196

 

原创地址:https://www.cnblogs.com/rjzheng/p/11430592.html

所以在Redis之间进行数据交换的时候消息头所占空间为CLUSTER_SLOTS/8,

也就是16384÷8÷1024=2kb      公式:1bit=8b(byte)=1024kb

如果是65536的话就会有8kb的数据大小,有点浪费了带宽,而且Redis的节点数量不会超过1000个,已经够用了,超过1000个会造成网络拥堵

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值