why redis-cluster use 16384 slots? crc16() can have 2^16 -1=65535 different remainders。

Comment From: antirez

The reason is: 1. 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. 2. 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.

Comment From: exceptionplayer

Hey,i have two questions about you answer:

  1. why 8K of space is prohibitive using 65 slots?
  2. why the bitmap should be compressed?

Comment From: mind4s

@Medusar 1. not 65, that's 65k = 8 * 8 (8 bit/byte) * 1024(1k) = 8K bitmap size 2. Compress bitmap to reduce network traffic

Comment From: exceptionplayer

@foojolt thank you very much

Comment From: courage007

why: 16k was in the right range to ensure enough slots per master with a max of 1000 maters. what is the logic in the background?

Comment From: guoruibiao

thx. The balance of bitmap's size and number of master is the key.

Comment From: qfl19911216

what is other design tradeoffs? @foojolt

Comment From: qfl19911216

8K bitmap size means that bitmap size is 8 bits? @foojolt

Comment From: qfl19911216

How to understand the sentence not 65, that's 65K = 8 * 8 (8 bit/byte) * 1024 (1k) = 8K bitmap size?@foojolt

Comment From: haiyuzhu

How to understand the sentence not 65, that's 65K = 8 * 8 (8 bit/byte) * 1024 (1k) = 8K bitmap size?@foojolt

crc16() can have 2^16 -1=65535, which means the bitmap has 65535 bits. so the size of the bitmap can be calculated by 65535 / 8 (8bit/byte)/1024(1k)=7.99 Kbytes.

Comment From: cqlxcnp

Thanks for answers

Comment From: shao-h

How to understand the sentence not 65, that's 65K = 8 * 8 (8 bit/byte) * 1024 (1k) = 8K bitmap size?@foojolt

crc16() can have 2^16 -1=65535, which means the bitmap has 65535 bits. so the size of the bitmap can be calculated by 65535 / 8 (8bit/byte)/1024(1k)=7.99 Kbytes.

Hi, I didn't find where to compress the slots bitmap in source code, did I miss something?

Comment From: trevor211

How to understand the sentence not 65, that's 65K = 8 * 8 (8 bit/byte) * 1024 (1k) = 8K bitmap size?@foojolt

crc16() can have 2^16 -1=65535, which means the bitmap has 65535 bits. so the size of the bitmap can be calculated by 65535 / 8 (8bit/byte)/1024(1k)=7.99 Kbytes.

Hi, I didn't find where to compress the slots bitmap in source code, did I miss something?

No compression, just 1 bit for 1 slot. See the code: https://github.com/antirez/redis/blob/ac441c741379dd4002f664c81047e8412cb793d0/src/cluster.h#L117

Comment From: sjclijie

mark

Comment From: zjwwf

why 16k was in the right range to ensure enough slots per master with a max of 1000 maters?

Comment From: trevor211

I think @antirez has already made it clear:

The reason is:

  1. 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.
  2. 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.

In a nutshell, it is the result of a balance between message size and average number of slots held by a master.

Comment From: closeable

mark

Comment From: khakili

Mark

Comment From: trevor211

This is issue is quite old, yet I was asked this same question for so many times even after @antirez had already given his answer. Maybe it's the language gap. I think @antirez has already made it clear in English, and I don't want to be superfluous. Following is my understanding in Chinese: 总结: 1、消息大小考虑:尽管crc16能得到65535个值,但redis选择16384个slot,是因为16384的消息只占用了2k,而65535则需要8k。 2、集群规模设计考虑:集群设计最多支持1000个分片,16384是相对比较好的选择,需要保证在最大集群规模下,slot均匀分布场景下,每个分片平均分到的slot不至于太小。

需要注意2个问题: 1、为什么要传全量的slot状态? 因为分布式场景,基于状态的设计更合理,状态的传播具有幂等性 2、为什么不考虑压缩? 集群规模较小的场景下,每个分片负责大量的slot,很难压缩。

Comment From: zhangyizong

@trevor211 sorry, i still cannot understand it. why can't i use 1024 bit for 1000 masters, thus only 128Byte is needed. if keys are well distributed between slots, thus, even though a master only have a slot in average, keys i think will be well distributed between masters

Comment From: yuxiao97

Mark.

Comment From: fangxiaoming

Mark

Comment From: SherlockGy

Mark

Comment From: trevor211

@trevor211 sorry, i still cannot understand it. why can't i use 1024 bit for 1000 masters, thus only 128Byte is needed. if keys are well distributed between slots, thus, even though a master only have a slot in average, keys i think will be well distributed between masters

Sorry for taking so long to reply. The thing is that if you allocate too few slots to a master, it would be impossible to migrate some keys to other masters. We may want to migrate hot keys to other nodes to alleviate the pressure on the server. As a consequence, it may be a better idea be able to allocate N slots to a single master, where N should not be too small or too big.

Comment From: IS908

@trevor211 sorry, i still cannot understand it. why can't i use 1024 bit for 1000 masters, thus only 128Byte is needed. if keys are well distributed between slots, thus, even though a master only have a slot in average, keys i think will be well distributed between masters

Sorry for taking so long to reply. The thing is that if you allocate too few slots to a master, it would be impossible to migrate some keys to other masters. We may want to migrate hot keys to other nodes to alleviate the pressure on the server. As a consequence, it may be a better idea be able to allocate N slots to a single master, where N should not be too small or too big.

mark. If use 1024 bit for 1000 master, then consistent hash will degenerate to normal hash.

Comment From: mroccyen

mark

Comment From: holiday-jq

mark

Comment From: 2227324689

mark

Comment From: walterlife

mark

Comment From: xp-go

Why isn't slot 8192?

Comment From: uestccls

m

Comment From: ysong6

mark

Comment From: softsheng

mark

Comment From: zhangyizong

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

Comment From: bubua12

Mark

Comment From: zhangyizong

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

Comment From: YvCeung

This is issue is quite old, yet I was asked this same question for so many times even after @antirez had already given his answer. Maybe it's the language gap. I think @antirez has already made it clear in English, and I don't want to be superfluous. Following is my understanding in Chinese: 总结: 1、消息大小考虑:尽管crc16能得到65535个值,但redis选择16384个slot,是因为16384的消息只占用了2k,而65535则需要8k。 2、集群规模设计考虑:集群设计最多支持1000个分片,16384是相对比较好的选择,需要保证在最大集群规模下,slot均匀分布场景下,每个分片平均分到的slot不至于太小。

需要注意2个问题: 1、为什么要传全量的slot状态? 因为分布式场景,基于状态的设计更合理,状态的传播具有幂等性 2、为什么不考虑压缩? 集群规模较小的场景下,每个分片负责大量的slot,很难压缩。

wow,subject representative!