Why redis-cluster use 16384 slots?

Quote:

1
2
3
4
5
6
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.

Mine:

CRC16() can have 2^16 -1 = 65535 different reminders, but 2^14 = 16384 is chosen.

Master nodes in a redis cluster: meet, then ping/pong regularly to exchange messages. This message:

1
2
3
4
5
6
7
8
typedef struct {
...
uint16_t type; // meet, ping, pong, etc
...
// size: 16384/8; bitmap slots; each slot: 0/1; 1: ある
unsigned char myslots[CLUSTER_SLOTS/8];
...
} clusterMsg;

Normal heartbeat packets carry the full configuration of a node...they contain the slots configuration for a node...uses 2k of space with16k slots, but would use a prohibitive 8k of space using 65k slots; conclusion:

ping: i.e. heartbeat, redis nodes send a number of ping messages as heartbeat packets. If #slots = 65536, ping msg head size is too large: waste bandwidth; 16384 slots are enough to carry the msg, yet not as large.