Skip to content

why redis-cluster use 16384 slots? #2576

Closed
@qunchenmy

Description

@qunchenmy

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

Activity

antirez

antirez commented on May 12, 2015

@antirez
Contributor

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.

exceptionplayer

exceptionplayer commented on Mar 12, 2016

@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?
mind4s

mind4s commented on Mar 17, 2016

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

exceptionplayer commented on Mar 17, 2016

@exceptionplayer

@foojolt thank you very much

courage007

courage007 commented on Jun 29, 2017

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

guoruibiao

guoruibiao commented on Jun 21, 2019

@guoruibiao

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

qfl19911216

qfl19911216 commented on Jul 23, 2019

@qfl19911216

what is other design tradeoffs? @foojolt

qfl19911216

qfl19911216 commented on Jul 23, 2019

@qfl19911216

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

qfl19911216

qfl19911216 commented on Jul 23, 2019

@qfl19911216

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

haiyuzhu

haiyuzhu commented on Oct 24, 2019

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

cqlxcnp

cqlxcnp commented on Oct 30, 2019

@cqlxcnp

Thanks for answers

shao-h

shao-h commented on Apr 16, 2020

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

trevor211

trevor211 commented on Apr 17, 2020

@trevor211
Contributor

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

sjclijie commented on Sep 28, 2020

@sjclijie

mark

14 remaining items

holiday-jq

holiday-jq commented on Sep 16, 2022

@holiday-jq

mark

2227324689

2227324689 commented on Oct 16, 2022

@2227324689

mark

walterlife

walterlife commented on Nov 12, 2022

@walterlife

mark

xp-go

xp-go commented on Apr 11, 2023

@xp-go

Why isn't slot 8192?

uestccls

uestccls commented on Jul 27, 2023

@uestccls

m

ysong6

ysong6 commented on Jan 9, 2024

@ysong6

mark

deleted a comment from zhangyizong on Feb 5, 2024
deleted a comment from zhangyizong on Feb 5, 2024
deleted a comment from zhangyizong on Feb 5, 2024
softsheng

softsheng commented on Mar 5, 2024

@softsheng

mark

zhangyizong

zhangyizong commented on Mar 5, 2024

@zhangyizong
bubua12

bubua12 commented on May 27, 2024

@bubua12

Mark

zhangyizong

zhangyizong commented on May 27, 2024

@zhangyizong
YvCeung

YvCeung commented on Dec 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:to-be-closedrequesting the core team to close the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @antirez@yossigo@sjclijie@trevor211@walterlife

        Issue actions

          why redis-cluster use 16384 slots? · Issue #2576 · redis/redis