Consistent hashing lab
Place nodes and virtual nodes on a hash ring, add and remove nodes, and compare how many keys move against the naive hash mod N rule.
Each tick is one virtual node. Keys are placed and settled: 20000 of 20000.
Keys per node
ring, keys on node hash mod N, keys on node
- imbalance, ring
- 1.32max / mean
- imbalance, mod N
- 1.02max / mean
- mean keys per node
- 4000
- nodes
- 5
Keys moved by the last change
Add or remove a node to see how many keys have to move.
| Node | Ring keys | Mod N keys | Ring arc share |
|---|---|---|---|
| Node 0 | 3019 | 4034 | 15.1% |
| Node 1 | 5282 | 3999 | 26.3% |
| Node 2 | 3796 | 4069 | 19.0% |
| Node 3 | 4829 | 3946 | 24.2% |
| Node 4 | 3074 | 3952 | 15.4% |
What to try
Each one sets up a starting point. Then make the change it describes.
Add one node
Leave the defaults and press Add a node once. Read the two moved percentages.
Look for. Hash mod N reshuffles most keys because almost every key changes remainder. The ring only moves the keys the new node takes over.
One point per node
Set virtual nodes to 1 and look at the imbalance and the keys-per-node bars.
Look for. A few random points leave arcs of very different length, so some nodes own far more keys than others.
Smooth it out with virtual nodes
Slide virtual nodes up toward 256 and watch the imbalance number.
Look for. More points per node average out the arc lengths, so the max over mean ratio drops toward 1.
Remove a node
Press Remove next to any node. Compare the keys moved.
Look for. The ring only moves the keys that node owned, spread across the survivors. Hash mod N reshuffles again.
Grow the cluster
Press Add a node four times in a row and watch the ring percentage after each.
Look for. The share of keys that must move on each join shrinks as the cluster grows, because the new node takes a smaller slice.
New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.
Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms