Try
↑ ↓ move↵ openesc close
In this lesson · topic 5 of 7
  1. 1. Why hash mod N hurts
  2. 2. The ring and virtual nodes
  3. 3. Add a node to the ring and to mod N
  4. 4. What the ring balances and what it leaves
  5. 5. How many virtual nodes is enough
  6. 6. Rendezvous hashing and Maglev tables
  7. 7. Check ownership, balance and hot keys

Topic 5

How many virtual nodes is enough

7 min read

The lab lets you slide virtual nodes from 1 to 256 and watch the imbalance fall. This topic gives you the rule behind that curve, so you can choose a count without running an experiment.

Why the spread shrinks as one over root V

A node with V points owns V arcs. Each arc has a random length. The node’s share of the ring is the sum of V of them. Adding up V independent random lengths makes the total’s relative spread shrink in proportion to 1 / √V. With one point per node the relative standard deviation is about 100 percent. With the counts below it is:

Points per node (V) Relative std. deviation
1 100%
10 32%
100 10%
256 6.3%
1000 3.2%

The shape matters more than the table. To halve the spread you need four times as many points. Going from 100 to 400 points per node cuts the spread from 10 to 5 percent, and costs four times the memory.

Predict first

A ring has 100 virtual nodes per node. You raise it to 400. By roughly what factor does each node's load spread shrink?

From spread to max over mean

The lab reports the busiest node divided by the average. With N nodes, the busiest node sits above the mean by a few standard deviations, and the number of deviations grows with N. For eight nodes the expected maximum of eight normal values is about 1.4 standard deviations above the mean. That gives a rough estimate of 1 + 1.4 / √V:

  • V = 100: about 1.14.
  • V = 256: about 1.09.
  • V = 800: about 1.05.

The lab’s seeded run with 256 points reads 1.12measured, which is inside the noise of one seed around the estimate. At V = 1 the normal approximation is poor. The largest of eight random gaps on a circle averages about 2.7 times the mean gap, and the lab’s seed shows 2.05measured, which is one draw from a wide spread.

To hit a target of 1.05 with eight nodes, solve 1.4 / √V = 0.05, which gives V ≈ 800.

Bigger clusters need more points

The busiest of 1,000 nodes is not 1.4 deviations above the mean but about 3.2, because there are more draws to produce an outlier. The same V = 100 that gives 1.14 on eight nodes gives about 1 + 3.2 × 0.10 = 1.32 on a thousand. To reach 1.05 on a thousand nodes you need V ≈ (3.2 / 0.05)² ≈ 4,000.

That is the real trade-off, and the cost now shows. A thousand nodes at 4,000 points each is four million ring entries. At 16 bytes a point, which is a 64-bit hash and an owner id, that is 64 MB for every client that holds the ring, and every membership change rebuilds a structure of that size. Lookup stays cheap, since a binary search over four million entries takes about 22 comparisons, but memory and rebuild time do not.

Because of this, large systems tend to stop pushing the count up. They accept a loose bound, use a different balancing scheme such as a bounded-load variant, or move the placement decision into a lookup table, which the next topic covers.

Sources

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms