Skip to content

Never let time lead a key that every write touches

In an ordered key-value store, a key that starts with a rising timestamp sends new writes near the end of one range. The storage team that holds that end can limit the whole cluster. We ran a historical A/B test at 30 storage hosts. It spread fdyno's time-led extra write record keys over 64 fixed prefixes. At matched load, the hottest storage server's input fell from 3.96 to 1.72 times the median. The highest sustained offered rate rose 32%, from 201,136 to 266,002 operations per second (cluster version 9, prefixes off to on; runs fdyno-hab10xa-a1 and fdyno-hab10xb-a1, build a2f43417).

Update: extra write records removed

An extra write record was the record that builds before cdb6320c wrote for every write request. Later builds, including v0.1, write none. After an unknown commit, fdyno retries only a tokened transaction; every other write returns HTTP 500 transaction outcome may be unknown (fdyno's own retries). The results below describe the builds that wrote them. The key-layout lesson still applies to any key that every write touches.

The symptom: more storage, less return

We ran one fdyno workload on 3, 6, 15 and 30 FoundationDB storage hosts and changed nothing else (scaling-curve record). These runs used FoundationDB ssd-redwood-1, the build default, cluster version 3, prefixes off (fdyno-sc1x-a1, fdyno-sc2x-a1, fdyno-sc5x-a1, fdyno-sc10x-a1). The mix was 60% reads and 40% writes. Ten times the storage gave 4.5 times the throughput.

Storage hosts Best sustained ops/s Efficiency
3 44,959 1.00
6 79,790 0.89
15 159,588 0.71
30 201,113 0.45

Efficiency is the best sustained rate at n units of three storage hosts over n times the rate at one unit. Each point was one bounded-concurrency ladder: the offered rate rose in steps 1.15 times apart, and each worker waited for its response. A step counted as sustained only if it met four limits:

  • every operation type got at least 95% of its offered rate;
  • errors stayed at or below 0.1%;
  • every p99 stayed at or below 250 ms;
  • loader CPU stayed at or below 80%.

The p99 measures latency after dispatch, not how long an offered request waited to be sent. So these are the best tested steps, not hard capacity limits.

The limit changed as the cluster grew. The evidence is one mid-step status json sample per step: smoothed rates, and MVCC input, not application bytes.

  • 3 and 6 hosts: storage CPU. At the first failing step, 5 of 6 and then 10 of 12 storage processes ran at 0.9 core or more. The busiest took 1.2 to 1.4 times the median input. This is the healthy limit: add storage, get more.
  • 15 hosts: a hot subset. Five or six of 30 storage processes ran at 0.9 core or more, but the median fell to 0.70–0.78 core. The busiest took 2.2 to 2.4 times the median input.
  • 30 hosts: one hot server. Ratekeeper throttled the whole cluster on storage write queues. The server it named took 164 MB/s of input, 5.5 times the median, at 0.81 core. The median process used less than half a core.

The last line is the failure mode. FoundationDB's ratekeeper holds each storage server's write queue near a target. If the queues on more than one machine grow past it, it slows new transactions for the whole cluster. It skips one machine that falls behind. But a hot range lives on a whole team, so every replica of it falls behind together.

That is how one hot range can limit a whole cluster. More hosts lower the median. They do nothing for the hot range.

Why a time-led key makes one hot range

FoundationDB keeps keys in sorted order. It splits the key space into contiguous ranges, and each range lives on one team of storage servers. A key that starts with a rising timestamp sorts after the keys written before it. So new keys land near the end of the last range.

Splitting does not fix this. When FoundationDB splits the busy range, new keys go to the new last part. The tail moves, and the load moves with it. At any moment, the team that holds the tail takes the appends.

Builds before cdb6320c wrote an extra write record in the same transaction as each protected write. So a retry could find the first attempt's result. Before prefixes, in the default layout we tested, a record ID had three parts:

  1. one shard byte: a hash of the process's start-up identity, mod 4;
  2. the writer's clock in milliseconds;
  3. random bits.

Writer clocks differ a little, but new records still appended near four points. The expiry index that cleanup read was keyed by deadline minute, so every index append landed in the newest minute's range. Every record append went to one of four metadata tails and to that one index range.

The scaling-curve runs had no complete key map; the maps from the test below fit this. With prefixes off, each of the three hottest storage servers held an active record tail. At 30 hosts the hottest held the tails of two metadata shards and of one index shard. The controlled comparison is the evidence.

The fix: a fixed prefix before time

At version 9, each new operation ID started with a prefix: 0 to 63, picked at random when the ID was made. Record metadata keys got 64 prefixes instead of 4. The expiry index became (lane, deadline minute, ID), where lane is the prefix. Each prefix still appended at its own tail, but FoundationDB could place the 64 tails on different teams; the prefixes do not force it. In the test, the 64 index tails sat on 43 distinct teams at 15 hosts and on 50 at 30 hosts.

The prefix was part of the ID, so every attempt and retry used the same keys. The prefix count was fixed. Prefixes started when a process saw cluster version 9 active, at its next registration renewal after finalize; there was no setting. Cleanup drained all 64 prefixes and the old index, each oldest deadline first. Time still ordered the keys inside a prefix. It did not come first.

Version 10 kept the 64 prefixes but dropped the index: inside a prefix, records sorted by deadline, and cleanup cleared each prefix's expired range. The test below measured version 9.

The test

We ran the same binary on fresh clusters in one Availability Zone, at 15 and 30 storage hosts. Run A had prefixes off, and run B had them on (A/B record). The measured build (a2f43417, cluster version 9; runs fdyno-hab5xa-a1, fdyno-hab5xb-a1, fdyno-hab10xa-a1, fdyno-hab10xb-a1) switched prefixes with an environment variable. The landed code has no switch and adds review fixes that the runs did not measure.

Prefixes off → on 15 hosts 30 hosts
Best sustained offered ops/s 159,600 → 211,070 201,136 → 266,002
Hottest server input at matched load, MB/s 75.9 → 51.6 117.4 → 39.5
Hottest / median at matched load 1.86 → 1.36 3.96 → 1.72

Matched load means both runs of this version 9 A/B ran the same offered rate: 138,783 ops/s at 15 hosts and 174,901 at 30. The separate fixed-rate soak reused 174,901 ops/s (cluster version 10 with its deadline layout; run fdyno-v10c10x-a2, build 666d48f3), not a ladder step. The achieved rate of every operation type was within 0.01% between runs. So the input difference comes from the layout, not from more work. Input here is FoundationDB MVCC input from status counter deltas, not application bytes.

At both sizes, prefixes raised the best sustained step by two steps, 32%. With prefixes off, and with prefixes on at 15 hosts, ratekeeper named the storage write queue at the first failing step. At 30 hosts with prefixes on, it named no storage reason; the limiters named at that step were coordinator and log CPU.

The limits of this test, stated once:

  • One run per layout, so there are no error bars.
  • One Availability Zone, one workload mix.
  • The step size, 15%, is the resolution: 32% is two steps.
  • Metadata prefixes and index prefixes changed together, so the test does not say which mattered more.

The next limit

In the scaling curve at 30 hosts, all 12 transaction logs ran at 0.91 to 0.98 core: a risk, not a measured limit. The runs do not show whether coordinator or log CPU would stop the next step. The log tier stayed fixed in every run, and adding storage hosts does not add logs.

At 10× storage, cluster version 10 with its deadline layout sustained 305,902 offered ops/s once (fdyno-v10l10x-a1). Updates reached 95.29% of their target, slightly above the 95% threshold. A repeat (fdyno-v10l10x-a3) missed that step with updates at 89.27%. The results put the bend around 266,000–306,000 offered ops/s, but do not establish a ceiling or a bottleneck.

What to do with this

  • Never lead a key that every write touches with a timestamp, a sequence number or a counter. Put a small fixed prefix or hash first. Keep the count fixed, so that every reader and cleanup job knows every prefix. Keep it small, so that a scan of all prefixes stays cheap. fdyno used 64.
  • Pick the prefix once and store it in the key or ID. A retry, a reader and a cleanup job must all compute the same key.
  • Keep time second when you need order. Time right after the prefix still lets cleanup take the oldest entries first.
  • Measure per-server write input at matched load. Watch the hottest server over the median, not totals. If that ratio grows as you add servers, suspect the key layout before the hardware.
  • Test a layout with a controlled comparison. A map of which server holds which range shows ownership, not load. Run both layouts at the same offered rate and compare the hottest server.