为什么Redis的hash slot设置为16384
Redis 大约 1269 字问题
Redis
使用CRC16
算法(CRC16(key) % 16384
)可以产生2^16-1=65535
个值,但为什么哈希槽设置成了16384
?
原因
https://github.com/redis/redis/issues/2576
The reason is:
- 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.
- At the same time it is unlikely that Redis Cluster would scale to more than 1000 mater nodes because of other design tradeoffs. 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. 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.
- 正常的心跳数据包带有节点的完整配置。而
16k
大小的槽数量所需要耗费的内存为2k
,但如果使用65k
个槽,这部分空间将达到8k
,心跳信息就会很庞大。 Redis
集群中主节点的数量基本不可能超过1000
个。
16k
个槽当主节点为1000
的时候,是刚好比较合理的,既保证了每个节点有足够的哈希槽,又可以很好的利用bitmap
。 注意:在小型群集中,bitmap
将难以压缩,因为当N
较小时,bitmap
将有slot/N
个比特位,在btimap
中占很大一部分比特位。
查看 key 的 hash slot
cluster keyslot mykey
输出
192.168.100.1:6380> CLUSTER KEYSLOT mykey
(integer) 14687
阅读 73 · 发布于 2021-03-20
————        END        ————
扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Spring Boot使用MongoDB实现共享Session阅读 950
-
Java 中的锁 StampedLock阅读 24
-
Linux修改文件执行权限阅读 612
-
MySQL备份工具xtrabackup安装和使用阅读 54
-
Nginx配置之解决413错误(Request Entity Too Large)阅读 2027
-
Notepad++保存Ctrl-S显示DC3,搜索Ctrl-F显示ACK解决办法阅读 3005
-
Java8 @FunctionalInterface注解阅读 461
-
OpenResty使用lua-resty-upload上传文件阅读 85
-
走进Rust:函数阅读 371
-
Linux tac倒序查看文本内容阅读 685