Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why redis cluster only have 16384 slots?

Tags:

In my opinion, with the development of keys, the 'hash conflict' will occurs more and more frequently. I have no idea if those keys on the same slot are stored in singly linked list, then read performance will be effected, especially the stale record?

like image 777
Carl H Avatar asked Mar 24 '16 15:03

Carl H


People also ask

How many hash slots are there in Redis?

There are 16384 hash slots in Redis Cluster, and to compute the hash slot for a given key, we simply take the CRC16 of the key modulo 16384.

How many nodes can a Redis cluster have?

A cluster is divided up among 16,384 slots — the maximum number of nodes or shards in a Redis cluster.

How big can a Redis cluster be?

The cluster's key space is split into 16384 slots, effectively setting an upper limit for the cluster size of 16384 master nodes (however, the suggested max size of nodes is on the order of ~ 1000 nodes).

What is the difference between Redis and Redis cluster?

The Redis Cluster supports only one database - indicated if you have a big dataset - and Redis supports multiple databases. The Redis Cluster client must support redirection, while the client used for Redis doesn't need it.


2 Answers

answer from antirez, the author of Redis, below.

The reason is:

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

like image 99
ponypaver Avatar answered Oct 11 '22 14:10

ponypaver


These "slots" are merely a unit of distribution across shards. You're not going to have of 16K shards servers in a cluster; but the are granular enough to allow some degree of weighted load distribution. (For example if you start with four shard on one type of hardware and choose to introduce two more of a more power profile, you could make the new servers targets for twice as many slots as the existing servers and thus achieve a more even relatively utilization of your capacity.

I'm just summarizing the gist of how they're used. For details read the Redis Cluster Specification.

like image 31
Jim Dennis Avatar answered Oct 11 '22 15:10

Jim Dennis