Where a concurrent put spends its time
The concurrency row of the acceptance bars (ADR-0005) asked that, up to K=8 threads on one saver, our put p50 stay within 3× of
our own K=1 p50. On the plain graph it has missed at every stage: 3.57× at stage 3 and 5.17× at
stage 8 (claimed here from records kept before public release; those runs' ledgers are not in
this repository). This note records where the K=8 time goes.
Method
four_arm.py's concurrent workload, in a run before public release (measured; a
dedicated host of 4 CPU, contended: false, 3 repetitions of 100 turns per thread, pool of 8). The
timed CoreSaver splits each put at the saver's three choke points (_connection, _fetch,
_on_codec_thread):
| Part | What it is |
|---|---|
| pool wait | waiting for a pool connection |
| statement | the statements, from sending to the coroutine running again, the pool wait excluded |
| codec queue | submitted to the codec thread until it starts this put's work |
| codec run | the codec thread doing this put's work (serialize, compress, patch) |
| codec resume | the work done, until the coroutine runs again |
| other | the rest of aput |
A task running asyncio.sleep(0.001) in a loop beside the threads records how late the event
loop wakes it (loop lag, _loop_lag).
Result — measured
Plain graph, ours with patches; p50s, the range across the three repetitions:
| Part | K=1 | K=8 |
|---|---|---|
put p50 (median of the repetitions) |
2.26 ms | 8.19 ms (3.62×) |
| pool wait | 0.01–0.02 ms | 0.01 ms |
| statement | 1.10–1.56 ms | 2.76–2.85 ms |
| codec queue | 0.13–0.22 ms | 1.57–1.79 ms |
| codec run | 0.42–0.78 ms | 0.47–0.49 ms |
| codec resume | 0.18–0.26 ms | 2.54–2.62 ms |
| other | 0.06–0.09 ms | 0.05 ms |
| loop lag | 0.34–0.42 ms | 2.03–2.08 ms |
| client CPU per turn × turns/s | 0.74–0.77 s/s | 1.14 s/s |
- The pool and the codec work do not grow: pool wait stays at 0.01 ms and codec run at about 0.5 ms per put.
- What grows is waiting for the event loop. Codec resume rises from about 0.2 to 2.6 ms, as loop lag rises from 0.4 to 2.1 ms. Statement time rises by about 1.6 ms, less than one loop lag.
- The process is out of CPU. At K=8 the benchmark process uses 1.14 CPU-seconds per second: one Python process running eight graphs, the saver's coroutines and the codec thread under one interpreter lock. Each of a put's three awaits then waits its turn behind the other threads' graph steps.
- The codec queue is mostly the same contention (
inferred): the codec thread does about 0.5 ms of work per put, which keeps it busy at most a quarter of the time (three puts a turn at 186 turns a second), yet a put waits 1.6–1.8 ms for it to start. The thread is mostly waiting for the interpreter lock rather than for other puts. - Ours in full-copies mode shows the same pattern with less codec work: 7.41 ms at K=8, and loop lag 3.1–3.4 ms.
- Upstream at K=8 is 22.4 ms p50, nearly all of it waiting for its saver-wide lock, and it manages 60 turns a second against ours' 181–195.
- Between runs the ratio moves: this run reads 3.62×, stage 8 read 5.17× (
claimed, from its run), and in full-copies mode 2.29× here. The K=1 p50 alone moved from 2.2 to 3.6 ms between repetitions. Dividing two small medians amplifies that noise.
Note (2026-11-18): the client CPU and loop lag figures above include the lag sampler's own
cost. In this run the 1 ms sampler ran beside the threads inside the measured window, so its
CPU and its loop turns were charged to client CPU per turn, to turns/s and to the waits inside
each put. On an idle event loop the sampler costs about 150 ms of CPU per wall second
(measured in the pre-release review). Its share under this load was not measured (inferred to be smaller, since a busy
loop wakes it less often). four_arm.py now takes loop lag from one extra run per arm that
reports nothing else. The figures stand as recorded.
What it means — inferred
At K=8 our put latency is set by the CPU of the one process that drives the graphs, not by the
saver's pool, server or codec. A saver change could only lower the CPU each put costs (patching
adds 0.6–1.0 ms of client CPU per turn over full copies), which shortens the queue but cannot
remove it while the process is saturated. The 3× ratio therefore measures the benchmark process
more than the saver.