Measuring a Log on Object Storage

Reading time:1962 words, 10 min read
Last edited:
Measuring a Log on Object Storage

Part 5 of a series on commit, written while building CambiumDB. Part 4: Design It Twice

Part 4 chose a design for CambiumDB: one owner per namespace, batching writes into log segments on object storage, each committed with one create-only PUT. That design rests on a few numbers. How long does a PUT take? What happens when two writers race for the same segment? Does batching cost much latency? How long does a new owner take to load a namespace? Before committing to the design, I measured them. This post is just those measurements.

How I measured

A small Rust harness (aws-sdk-s3, SDK retries off, so a throttled request shows up as an error instead of a slow success) ran against three backends:

Read these with three caveats:

  • One run, one afternoon. Each number is a single run (300 requests per latency cell, 20 seconds per group-commit cell, median of 3 for cold start). S3 latency varies over time, and the p99 values in particular reflect this window only.
  • Same availability zone is the best case. A client in another zone pays more on Standard, and much more on Express, which lives in one zone.
  • The SeaweedFS numbers are a floor, not a deployment figure. There's no network hop and no replication, and the laptop wasn't idle.

There were no request errors on S3, and every conditional write behaved as promised: a second create-only PUT and a PUT with a stale ETag both got a 412.

The whole AWS run cost about 15 cents.

A single small request

Latency of a 4 KiB request, p50 (dot) to p99 (end of line), on a log scale. S3 Standard is about 22-27 ms at p50, S3 Express about 7 ms, local SeaweedFS about 1-2 ms. On S3 Standard, If-Match is slower, with a p99 of 93 ms.

4 KiB, ms (p50 / p99) S3 Standard S3 Express SeaweedFS (local)
PUT 22.4 / 38.2 7.3 / 9.6 1.35 / 1.71
PUT If-None-Match: * 26.5 / 40.5 7.4 / 8.3 1.55 / 1.94
PUT If-Match 39.0 / 92.9 7.3 / 8.2 1.73 / 2.17
GET 22.8 / 34.1 4.6 / 5.5 0.81 / 1.16
  • S3 Standard is faster than I'd assumed. I'd budgeted 50 to 100 ms per PUT. From the same zone, a small PUT was 22 ms at p50 and under 40 ms at p99. The 50 to 100 ms range fits 4 MiB objects (66 ms p50) or, plausibly, a client in another zone.
  • S3 Express is about three times faster at p50, five times at p99, and very tight. Its p99 sits within 1 or 2 ms of its p50.
  • Create-only is nearly free; If-Match on Standard isn't. If-None-Match: * added about 4 ms. If-Match added about 17 ms and a much longer tail. That comparison isn't clean, though: the harness wrote If-Match as overwrites of one key and the others as new keys, so it can't tell "conditional" apart from "overwrite." Either way, Design B only ever creates new keys.

Racing for one segment

Design B fences an old owner by racing it for the next segment: both send a create-only PUT to the same key, and exactly one wins. So the race has to be atomic, and losing has to be quick.

The harness raced 2, 4 and 8 writers for 200 keys each, then read each key back to check that exactly one writer won and the stored bytes were the winner's.

Median latency for a writer that loses a create-only race, by number of writers racing. S3 Standard losers take a flat 80 ms and S3 Express 9 ms. SeaweedFS losers are fast with 2 writers but stall about 1 s with 4 and 3 s with 8.

loser p50, ms 2 writers 4 writers 8 writers
S3 Standard 79.9 80.6 80.2
S3 Express 9.2 8.9 9.4
SeaweedFS (local) 2.1 1,007 3,007
  • No atomicity violations on any backend: 600 contended keys each, every one with exactly one winner, and every loser got a clean 412.
  • Winners weren't slowed down by contention anywhere: about 21 ms on Standard, 7 ms on Express.
  • S3 losers pay a flat cost. Standard losers take about 80 ms, Express about 9, no matter how many writers race.
  • SeaweedFS losers stall in whole seconds. With 4 writers a loser waits about 1 s, with 8 about 3 s, clustered at exact multiples of one second. It looks like contenders wait behind a lock with a 1-second retry, though I inferred that from the timings, not the source. With 2 writers, the realistic failover case (the old owner and the new one), losing took 2 ms.

The practical result: on S3, an owner that loses a race knows within a fraction of a second. On SeaweedFS, anything waiting on a loser's answer needs a timeout of several seconds.

Group commit

The owner batches every op that arrives during a window of W milliseconds, then writes them all as one segment. The model from part 4 says an op's acknowledgement should take about the window plus one PUT. This test offered a steady stream of 200-byte ops, open loop, for 20 seconds per cell.

Acknowledgement latency at 1,000 ops per second against the batch window. Median latency is roughly the window plus one PUT: about 24 ms on S3 Standard, 7 ms on S3 Express, 2-5 ms on local SeaweedFS. Shaded bands reach p99.

1,000 ops/s, ack ms (p50 / p99) W = 0 W = 10 W = 50 W = 100
S3 Standard 37.3 / 70.1 44.0 / 83.2 64.5 / 108.4 88.1 / 152.7
S3 Express 11.2 / 15.5 16.8 / 26.8 37.2 / 66.3 62.7 / 116.1
SeaweedFS (local) 3.1 / 6.5 10.2 / 18.5 32.5 / 60.6 58.6 / 110.8

The model holds: each line runs parallel to "the window alone," offset by about one PUT. As the window grows, the backends converge, because the window dominates. At W = 50 ms, Express is within 5 ms of the local SeaweedFS.

Throughput was never the limit. Every backend absorbed 5,000 ops per second at every window size.

What the window buys is fewer requests:

PUT requests per second needed to commit 1,000 ops per second, against the batch window, on a log scale. With no window, S3 Standard needs 40, S3 Express 138 and SeaweedFS 565. A 100 ms window brings all three to about 8-9.

1,000 ops/s, PUTs per second (ops per segment) W = 0 W = 10 W = 50 W = 100
S3 Standard 40.5 (25) 27.3 (37) 13.1 (77) 8.0 (126)
S3 Express 137.6 (7) 54.3 (18) 17.1 (59) 9.2 (109)
SeaweedFS (local) 565.1 (1.8) 70.6 (14) 18.1 (55) 9.4 (106)

With no window, the owner commits as soon as the previous PUT returns, so the request rate is just one over the PUT latency: about 40 commits a second on Standard, 138 on Express. That's the ceiling for one owner's commit chain, and it's well above the "about 15 per second" I quoted in part 1. That figure came from a benchmark of compare-and-swap on one object, a different operation. Each segment carries many ops, so that ceiling is on commits, not on ops.

A window of 10 ms costs 5 to 10 ms of median latency and cuts the requests by 2.5 times on Express and 8 times on SeaweedFS. On Standard it also fixed the tail. At 5,000 ops per second with no window, the p99 hit 232 ms, because ops queued behind the one in-flight PUT. With a 10 ms window it dropped to 70 ms, using fewer requests.

Picking a window

The latency chart and the requests chart are one trade-off seen from two sides: a bigger window costs latency and saves requests. To pick a window, read them the way you'd read a scree plot in PCA. Look for the elbow, the point after which each extra unit of cost buys much less than the one before it.

Putting the two together as a rate makes the elbow easier to see than the lines do. This is PUTs per second saved for each millisecond of median latency added, between neighbouring window sizes:

PUTs/s saved per ms of p50 added W 0 → 10 W 10 → 50 W 50 → 100
S3 Standard 2.0 0.7 0.2
S3 Express 14.9 1.8 0.3
SeaweedFS (local) 69.6 2.4 0.3
  • On Express and SeaweedFS the elbow is at about 10 ms. The first 10 ms of window does most of the work. Past it, each extra millisecond saves roughly a tenth as many requests, and past 50 ms almost none.
  • On Standard there's no sharp elbow. A 22 ms PUT already batches about 25 ops on its own, so the window has less to add. The rate still falls by about three times at each step, and 10 ms is still worth it for the tail at high load.
  • Where you sit relative to the elbow depends on what a request costs you. If requests are cheap and latency matters, stay at or left of it. If you pay per request at high volume, moving right of it still saves something, just less for each millisecond.

Two caveats. I measured only four window sizes, so the real elbow could sit anywhere between about 5 and 50 ms; a finer sweep would place it. And the requests chart uses a log scale, which flattens the first drop, so the table is a better guide than the slope of the lines.

So the window is a latency budget, not a correctness setting: W = 10 ms gives about 17 ms p50 and 27 ms p99 on Express, and 44 and 83 ms on Standard.

Cold start

A new owner (after a failover, say) has to load the namespace's last checkpoint (a snapshot of the whole index), decode it, then fetch and replay the log segments written since. The test used a checkpoint of 66 bytes per path and a tail of 100 segments of 64 KiB (about 33,000 ops), fetched 16 at a time.

Cold start at one million paths, split into checkpoint download, decode and log tail. SeaweedFS local 288 ms, S3 Express 721 ms, S3 Standard 1,090 ms. Downloading the 66 MB checkpoint is most of it on S3.

cold start, ms 10,000 paths 100,000 paths 1,000,000 paths
S3 Standard 265 324 1,090
S3 Express 93 135 721
SeaweedFS (local) 35 60 288
  • A million paths load in about a second on Standard and 0.7 s on Express. That's fine for a failover measured in seconds.
  • The checkpoint download is most of it: 693 ms of 1,090 on Standard, at about 95 MB/s from a single stream. Downloading it in parallel ranges, or splitting the checkpoint, is the one change that would matter. I haven't tested either.
  • Decoding takes about 165 ms at a million paths on every backend. That's CPU, and mostly this harness's naive decoder, which allocates a string per path.
  • The tail is latency-bound, not bandwidth-bound. A hundred segments fetched 16 at a time is 7 rounds of requests: about 200 ms on Standard, 40 on Express. Replaying 33,000 ops took about 10 ms.

What changed

I'd assumed I measured
An S3 PUT takes 50 to 100 ms 22 ms p50 on Standard from the same zone; 50 to 100 ms is a 4 MiB object
About 15 commits per second per owner About 40 on Standard and 138 on Express, each carrying a batch
Create-only races are atomic Held on all three backends: 0 violations in 600 keys each
Losing a race is slow On S3, a flat 80 ms (Standard) or 9 ms (Express); only SeaweedFS stalls
Commit latency is the window plus a PUT Confirmed, with the PUT at 24 ms on Standard and 7 ms on Express
Cold start at a million paths is 1-2 s 1.09 s on Standard and 0.72 s on Express, mostly the checkpoint download

Nothing here argued against Design B. It mostly turned the latency question into configuration: the protocol is the same on every backend, and the batch window is how you choose where to sit between latency and request cost.

Still unmeasured: clients in another zone or region, repeat runs at different times of day, many writers racing If-Match on one object, and the parallel checkpoint download.