首页  

为何RedisCluster设计成16384个槽     所属分类 redis 浏览量 1127
Redis集群
Redis Sentinal 高可用, master宕机时将slave提升为master 
Redis Cluster  扩展性,分片存储。

数据分片策略 Sharding
范围分片 哈希分片 一致性哈希   虚拟哈希槽

Redis 虚拟哈希槽 hashslot
16384 个槽位  (2的14次方)
slot = CRC16(key) & 16383

虚拟槽分区的优点
解耦数据和节点之间的关系,简化了节点扩容和收缩难度。
节点自身维护槽的映射关系,不需要客户端或者代理服务维护槽分区元数据
支持节点、槽和键之间的映射查询,用于数据路由,在线集群伸缩等场景。

为什么会设计成16384个槽

https://github.com/antirez/redis/issues/2576
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.

如果槽位为65536,发送心跳信息的消息头达8k,发送的心跳包过于庞大。
myslots[CLUSTER_SLOTS/8]

redis的集群主节点数量基本不可能超过1000个

槽位越小,节点少的情况下,压缩率高

16384÷8÷1024=2kb


Redis 集群伸缩 集群扩容 使用 cluster meet 命令,让新节点加入集群 cluster setslot { slot } importing { sourceNodeId } 命令,让目标节点准备导入槽的数据 cluster setslot { slot } migrating { targetNodeId } 命令,让源节点准备迁出槽的数据 cluster getkeysinslot { slot } { count } 命令,获取 count 个属于槽 { slot } 的键 migrate { targetNodeIp} " " 0 { timeout } keys { key... } 命令,把获取的键通过 pipeline 机制批量迁移到目标节点 cluster setslot { slot } node { targetNodeId } 通知槽分配给目标节点 集群收缩 下线节点 迁移槽数据 使用 cluster forget { downNodeId } 命令 将指定的节点加入到禁用列表中,在禁用列表内的节点不再发送 Gossip 消息。
Redis cluster 原理 大数据日知录第一章数据分片与路由读书笔记 aerospike数据分布

上一篇     下一篇
springboot2集成业务指标

Object的hashCode和equals方法

面向对象 六原则 一法则

java面试题

NoSQL 简介

zookeeper为何不适合做服务发现