Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why redis-cluster use 16384 slots? #2576

Closed
qunchenmy opened this issue May 12, 2015 · 34 comments
Closed

why redis-cluster use 16384 slots? #2576

qunchenmy opened this issue May 12, 2015 · 34 comments
Labels
state:to-be-closed requesting the core team to close the issue

Comments

@qunchenmy
Copy link

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

@antirez
Copy link
Contributor

antirez commented May 12, 2015

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.

@antirez antirez closed this as completed May 12, 2015
@medusar
Copy link

medusar commented Mar 12, 2016

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?

@mind4s
Copy link

mind4s commented Mar 17, 2016

@medusar

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

@medusar
Copy link

medusar commented Mar 17, 2016

@foojolt thank you very much

@courage007
Copy link

courage007 commented Jun 29, 2017

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?

@guoruibiao
Copy link

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

@qfl19911216
Copy link

what is other design tradeoffs? @foojolt

@qfl19911216
Copy link

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

@qfl19911216
Copy link

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

@haiyuzhu
Copy link

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.

@cqlxcnp
Copy link

cqlxcnp commented Oct 30, 2019

Thanks for answers

@shao-h
Copy link

shao-h commented Apr 16, 2020

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?

@trevor211
Copy link
Collaborator

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

@sjclijie
Copy link

mark

@zjwwf
Copy link

zjwwf commented Sep 28, 2020

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

@trevor211
Copy link
Collaborator

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.

@closeable
Copy link

mark

@khakili
Copy link

khakili commented Mar 11, 2021

Mark

@yossigo yossigo added the state:to-be-closed requesting the core team to close the issue label Mar 11, 2021
@trevor211
Copy link
Collaborator

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,很难压缩。

@zhangyizong
Copy link

zhangyizong commented Sep 15, 2021

@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

@yuxiao97
Copy link

Mark.

@fangxiaoming
Copy link

Mark

1 similar comment
@SherlockGy
Copy link

Mark

@trevor211
Copy link
Collaborator

@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.

@IS908
Copy link

IS908 commented Mar 20, 2022

@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.

@mroccyen
Copy link

mroccyen commented Jul 1, 2022

mark

1 similar comment
@holiday-jq
Copy link

mark

@2227324689
Copy link

mark

1 similar comment
@walterlife
Copy link

mark

@xp-go
Copy link

xp-go commented Apr 11, 2023

Why isn't slot 8192?

@uestccls
Copy link

m

@ysong6
Copy link

ysong6 commented Jan 9, 2024

mark

@redis redis deleted a comment from zhangyizong Feb 5, 2024
@redis redis deleted a comment from zhangyizong Feb 5, 2024
@redis redis deleted a comment from zhangyizong Feb 5, 2024
@softsheng
Copy link

mark

@zhangyizong
Copy link

zhangyizong commented Mar 5, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:to-be-closed requesting the core team to close the issue
Projects
None yet
Development

No branches or pull requests