Home  >  Article  >  Database  >  Why does redis have 16384 slots?

Why does redis have 16384 slots?

步履不停
步履不停Original
2019-06-24 11:30:435845browse

Why does redis have 16384 slots?

#Redis cluster does not use consistent hashing, but introduces the concept of hash slots. The Redis cluster has 16384 hash slots. Each key is checked modulo 16384 after CRC16 verification to determine which slot to place. Each node in the cluster is responsible for a part of the hash slot. But why is the number of hash slots 16384 (2^14)? This question was raised on github, and the author also gave an answer. Let’s briefly analyze it.

Why is it 16384 (2^14)?

When the redis node sends the heartbeat packet, all slots need to be put into the heartbeat packet so that the node can know the current cluster information. 16384=16k. When sending the heartbeat packet, it is compressed using bitmap. 2k (2 * 8 (8 bit) * 1024(1k) = 2K), which means that 16k slots are created using 2k space.

Although using the CRC16 algorithm can allocate up to 65535 (2^16-1) slots, 65535=65k, after compression it is 8k (8 * 8 (8 bit) * 1024(1k) = 8K), that is to say, 8k heartbeat packets are required. The author believes that it is not worth it; and generally a redis cluster will not have more than 1,000 master nodes, so the 16k slot is a more appropriate choice. .

Author's original words:

1. Ordinary heartbeat packets carry the complete configuration of the node. This configuration can be replaced with the old configuration in an idempotent manner to update the old configuration. . This means that they contain the node's slot configuration in its raw form, a 16k slot configuration would use 2k of memory, but using a 65k slot would use 8k of memory.

2. At the same time, due to other design compromises, the Redis cluster cannot be expanded to more than 1,000 nodes.

Therefore, 16k is more appropriate to ensure that each main device has enough slots, up to 1000. The node configuration information of redis is transmitted through bitmap storage. There is a compression process before transmission. The compression ratio has a great relationship with the number of slots and the number of nodes (because when N is small the bitmap would have slots/N bits set that is a large percentage of bits set.) [Number of slots/number of nodes] The larger N is, the smaller the compression ratio is.

For more Redis-related technical articles, please visit the Redis Tutorial## column to learn!

The above is the detailed content of Why does redis have 16384 slots?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn