~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
560 lines · 32.8 KB Raw History
# Grouped tables in the full relay

Grouped storage passed full signed-corpus validation and persisted replay after
restart. In the same-size live runs, index calls averaged 8.57 ms for grouped
zkv, 8.63 ms for legacy zkv and 9.12 ms for durable RocksDB. All live windows
hit the network cap, and reference-collector errors prevent coverage qualification.

The isolated relay can opt into grouped tables with `ZKV_TABLE_ENCODING=grouped`.
Legacy is still the default. Both use the same compiled binary, bounded index
maintenance profile, signature/proof policy, PostgreSQL, lalinsky/zio backend and
replay-disabled configuration. Production and Zeldi are untouched.

## Event-file durability boundary

The offline completion time ends after `DiskPersist.flush`, which performs a
positional event-file write but no fsync before advancing `committed_seq`.
Earlier captions called this a durable event flush; that wording was incorrect.
Synchronous collection-index writes are separate. Process-kill/restart checks
remain valid, while power-loss event durability is neither established nor
provided by this write-completion watermark. The live pilots explicitly disable
event replay, so this correction does not change their configured contract.
No runtime synchronization behavior has been changed silently in these comparisons.

## Two-minute startup probe

A disposable Fly VM with one performance vCPU, 2 GiB RAM and a 2 GiB root disk
connected to 2,008 upstreams and delivered 29,156 downstream events in 120 seconds.
The checking consumer observed no malformed CBOR, sequence reversals, gaps or
unexpected disconnects. The final sample had about 793 MiB relay RSS and 89 MiB
queued frame payload. Cold-start backlog had **not drained**; this is not a
steady-state qualification.

After stopping the relay, the index contained four grouped SSTs, no legacy or
unknown-format SSTs, and 1,379,751 total bytes. This confirms the real relay
exercised the requested format. It is not a matched-input size comparison.

The wrapper exported the observations, deleted the machine, checked absence of
volumes, deleted the app and verified its absence. The separate pre-existing
canary was left alone. Raw [resource and cleanup evidence](zkv-load/grouped-live/smoke/fly-resources.json),
[consumer checks](zkv-load/grouped-live/smoke/summary.json),
[format inventory](zkv-load/grouped-live/smoke/index-snapshot.json), and
[samples](zkv-load/grouped-live/smoke/samples.jsonl.gz) are retained.

## Grouped window stopped at the network cap

The first intended ten-minute window stopped after **571 seconds**, reaching the
observer's 4 GiB inbound-network budget. That counter includes the relay and
both reference subscriptions on Fly. It is not home-link traffic. It must not
be described as a completed ten-minute or steady-state qualification.

- The checking client received 248,991 events, with zero malformed CBOR,
  sequence reversals, gaps or unexpected disconnects; all 32 sampled membership
  checks passed. Replay remained disabled.
- The pilot saw 36,858 of the 40,486 DIDs seen by both reference relays:
  **91.04%** observed overlap. The reference collector reported an error
  (see below), so this is not qualified source-completeness evidence. A locally
  gap-free sequence does not establish source completeness.
- Final sampled queue: 7.52 MiB; maximum in the last two minutes: 10.80 MiB.
  Startup backlog shrank substantially but did not end at zero.
- Last measured interval: 521 events/s, 0.50 relay CPU cores and 0.997 whole-VM
  busy cores. The VM, including PostgreSQL and checking processes, was saturated.
  Relay RSS was 809 MiB. The live traffic mix differs from the earlier two-vCPU
  run, whose final delivery was about 300/s.
- Index calls averaged 8.57 ms including waits, **24.1%** of aggregate worker
  wall time. Authority checks accounted for 36.8%. These are overlapping worker
  intervals, not CPU attribution. Neither proves a read-decoder bottleneck.
- The stopped index contained four grouped SSTs (no other formats), with
  6,334,029 total index bytes. This is an end-of-run inventory, not matched-input
  storage-efficiency evidence or a measurement of deferred maintenance debt.
- Export, machine removal, volume absence and app absence were verified. The
  run does not prove graceful shutdown or restart recovery.

[Raw analysis](zkv-load/grouped-live/grouped/analysis.json),
[consumer checks](zkv-load/grouped-live/grouped/summary.json),
[cleanup evidence](zkv-load/grouped-live/grouped/fly-resources.json),
[metrics](zkv-load/grouped-live/grouped/samples.jsonl.gz), and
[relay-eval database](zkv-load/grouped-live/grouped/eval.db.gz) are retained.

The runner now rejects early network/exit stops as incomplete even when delivery
checks pass. Legacy zkv and durable RocksDB controls are running on the same
one-vCPU / 2 GiB size, with overlapping live windows. Both have durable index
writes; the earlier RocksDB live control used unsynced writes. The controls
will distinguish an engine effect from the heavier input and saturated VM.

## Matched-resource controls

All three intended 600-second windows reached the same 4 GiB network guard.
The controls exported their evidence and failed the completed-window gate as
intended. All machines/apps were deleted, with no volumes left.

| Observation | Grouped zkv | Legacy zkv | Durable RocksDB |
|---|---:|---:|---:|
| Checking-consumer window | 571 s | 576 s | 520 s |
| Events delivered to checker | 248,991 | 257,188 | 213,111 |
| Mean index-call wall time | 8.57 ms | 8.63 ms | 9.12 ms |
| Index share of aggregate worker wall time | 24.1% | 24.3% | 26.8% |
| Final queued payload | 7.52 MiB | 16.13 MiB | 7.71 MiB |
| Final whole-VM busy CPU | 1.00 cores | 1.00 cores | 0.99 cores |
| Final relay CPU | 0.50 cores | 0.50 cores | 0.50 cores |
| Final relay RSS | 809 MiB | 804 MiB | 862 MiB |
| Stream errors / membership checks failed | 0 / 0 | 0 / 0 | 0 / 0 |

Each run checked 32 memberships. Resource settings, zio, checker and evaluator
binaries, and durability guarantees match. The zkv variants use **the same
executable**, selecting table encoding at runtime. RocksDB uses its existing
adapter with `RELAY_INDEX_SYNC=true`; batching/deduplication internals still
differ. This is a comparison of complete application paths, not equal primitive
storage operations.

The similar index times across all three argue against attributing the current
slowdown to grouped-key reconstruction. The entire one-core VM is saturated;
index timings include owner/lock, I/O and scheduler waits. The relay itself uses
about half a core; PostgreSQL and checking processes also share the VM. The
controls do not establish how much of each index interval was CPU work.

![Observed processing queues](zkv-load/grouped-live/figures/queued_mib.svg)
![Observed relay CPU](zkv-load/grouped-live/figures/relay_cpu_cores.svg)
![Observed resident memory](zkv-load/grouped-live/figures/rss_mib.svg)
![Observed index-call wall time](zkv-load/grouped-live/figures/index.svg)

**Reference completeness is unqualified.** In every run the bsky.network
collector logged `EndOfStream`. The evaluator records `was_connected`, not a
full-window connection-duration guarantee, and its log lacks failure timestamps.
Its socket pump suppresses read errors after requested shutdown, so the logged
error is not the ordinary planned-close path, but its timing remains unknown.
The reference counts differ substantially between overlapping windows. Observed
DID-overlap ratios (91.0%, 94.5%, 84.0%) must not rank engines or establish
coverage. The coverage chart is intentionally omitted when collector errors are
present. Reference connection timing/failure must be measured before another
coverage qualification.

These operational observations do not replace the offline same-input disk and
read experiments. The retained bytes at the ends of these different live
windows are not a matched disk-efficiency comparison. No engine is qualified
for full steady-state relay capacity by this experiment; it identifies the
shared one-core limit and concrete measurement gaps without blaming the codec.

[Comparison data](zkv-load/grouped-live/comparison.json),
[legacy raw checks](zkv-load/grouped-live/legacy/summary.json),
[durable RocksDB raw checks](zkv-load/grouped-live/rocks/summary.json).
The next live test needs a sufficient but bounded network budget, reference
connection telemetry and a warm measurement interval. Replay-enabled load,
longer maintenance, offered-load capacity and abrupt-restart recovery remain
separate requirements of the larger audit.

The next corrected full-relay command runs from Zlay `codex/prefix-format-space`.
It uses the instrumented evaluator and a 6 GiB cap; the earlier raw resource
records identify the checkpoints that produced the 4 GiB-limited observations.

```sh
python3 scripts/zkv/fly_live.py \
  --binary /tmp/zlay-grouped-live-amd64/bin/zlay \
  --eval-binary /tmp/relay-eval-window-amd64/bin/relay-eval \
  --output /tmp/zkv-grouped-live-ten-minute \
  --seconds 600 --encoding grouped --cpu-kind performance --cpus 1 --memory 2048 \
  --network-mib 6144
```

The machine and relay have independent lifetimes; the local wrapper also cleans
up on failure. Live streams and reference subscriptions run exclusively on Fly.
Only compiled binaries/scripts and bounded result artifacts cross the home link.

## Offline persisted replay and restart

The existing atproto-bench signed corpus / real-relay harness passed with grouped
writing enabled: **3,300 delivered, 3,300 validated, zero skipped or failed**.
All memberships across 30 collections passed before and after a graceful restart;
the subscriber recovered all 3,300 persisted commits. Both on-disk SSTs had the
grouped format tag. The final index had one L0 table and 110 unflushed log
segments, below the configured 256-segment threshold; reopening recovered them.

This used native aarch64 Linux containers on the local ARM machine, Zig 0.17.0
ReleaseSafe/zio, a two-CPU / 512-MiB relay, one-CPU / 256-MiB PostgreSQL and the
existing separately capped oracle. The replay network was internal-only, image
pulls were disabled, and the corpus was mounted read-only. Resource cleanup was
verified. This is a correctness/burst/restart test, not an x86 live speed ranking
or a power-loss test. The initial attempt supplied the x86 Fly binary to the ARM
image and failed before the relay started; those resources were also removed.

[Corpus and resource fingerprints](zkv-load/grouped-live/offline-restart/environment.json),
[validation counters](zkv-load/grouped-live/offline-restart/counters.json),
[content checks](zkv-load/grouped-live/offline-restart/result.json), and
[restart checks](zkv-load/grouped-live/offline-restart/reopen.json).

```sh
zig build -Doffline-replay=true -Dbackend=zio -Dtarget=aarch64-linux-gnu \
  -Doptimize=ReleaseSafe -Dstrip=true -Dprofile-stages=true \
  --prefix /tmp/zlay-grouped-replay-arm64
python3 scripts/zkv/replay_run.py \
  --binary /tmp/zlay-grouped-replay-arm64/bin/zlay \
  --corpus /Users/nate/tangled.org/zzstoatzz.io/atproto-bench/fixtures/relay-corpus.bin \
  --output /tmp/zkv-grouped-offline-restart-arm64 \
  --count 3300 --rate 1000 --workers 16 --db-pool 20 --encoding grouped
```

## Reference-collector calibration

The evaluator now writes connection timestamps and terminal outcomes with
`--observations`. The native suite and real-socket CLI tests pass for healthy
shutdown, early peer close after a truncated frame, and rejected upgrades.
Both atomic commits passed their standalone checks through `git rebase -x`.
The evaluator is published on `zzstoatzz.io/relay`, branch
`codex/eval-window-telemetry`, checkpoint `786d33e`.

A 120-second Fly probe ran **only the two references**, without Zlay, PostgreSQL
or the CBOR checking client. Both ended by requested shutdown with no reported
errors. bsky.network delivered 67,315 events / 24,221 DIDs; relay.waow.tech
66,764 events / 24,150 DIDs. Their measured connected fractions were 99.85% and
99.58% (startup handshakes account for the remainder). Whole-VM busy CPU was
about 0.100 cores. Export and deletion of the app/machine were verified.
This short healthy window does not explain the delayed failures in the older
full-relay runs; a ten-minute reference-only window is next.

The runner checks terminal outcome and measured interval, with an explicit 99%
minimum connected fraction, plus nonempty events/DIDs. A connected-once flag
alone can no longer qualify a reference. This measures transport uptime, while
DID/revision comparisons remain the completeness checks.

[Timed observations](zkv-load/grouped-live/reference-probe/eval-observations.json),
[resources and cleanup](zkv-load/grouped-live/reference-probe/fly-resources.json),
[evaluator fingerprint](zkv-load/grouped-live/reference-probe/evaluator-build.json).

The existing Fly runner now accepts `--references-only`, so this isolation reuses
its lifetime, export and cleanup machinery. It installs only certificates and
process tools for that mode. No relay binary is uploaded or executed. All public
streams run on Fly. A failed interval remains an exported failed qualification.

Future full-relay windows can set `--network-mib 6144` explicitly. Valid budgets
are bounded to 512..8192 MiB and recorded in resources; defaults preserve the
old 512-MiB short / 4096-MiB long-window behavior. The extra budget addresses the
observed artificial cutoff rather than increasing the relay's CPU or memory.

## Offline signed-input screen

The existing ZDS fixture supplied the same 8,016 signed frames to all three
variants at an offered 600 frames/s, with 16 workers and a 20-connection DB pool.
The private Docker network had no Internet access. Each run validated and
delivered all frames, verified 1,601 collections, and passed persisted replay
and index checks after restart. All containers were removed.

![Short offline replay comparison](zkv-load/grouped-live/generated-screen/comparison.svg)

Completion through the final event-file write took 13.362 seconds for grouped
zkv, 13.659 for legacy zkv and 13.502 for durable RocksDB. This is one short trial
per variant, in grouped/RocksDB/legacy order. The input schedule itself takes
13.36 seconds, so these figures are an offered-load screen, not maximum throughput
or sustained relay capacity. Trial variability prevents a speed ranking.

CPU covers ingestion plus oracle readback; memory is the cgroup peak, including
charged cache, rather than process RSS. Maintenance runs normally, but completion
does not force-drain all compaction debt: grouped ended with 67 unflushed segments
and two L0 tables; legacy had 24 and two. This is not a zero-debt write-cost result.

[Raw results and corpus/binary hashes](zkv-load/grouped-live/generated-screen/summary.json).
Reproduce the chart with `python3 scripts/zkv/codec_replay_chart.py docs/measurements/storage/zkv-load/grouped-live/generated-screen`.

## Paired external-observer smoke

The two-minute paired test uses one performance CPU and 2 GiB per pilot, with
both reference collectors and both public pilot consumers on a separate VM.
RocksDB enables synchronous index writes; grouped zkv uses its bounded maintenance
profile. Both use ZIO, 16 frame workers, a 20-connection PostgreSQL pool, disabled
RAM/disk replay and the same public WebSocket handshake limits. No production
configuration changed. All three disposable apps were deleted and absence verified.

All four observer connections qualified for the full 120-second interval. Among
22,038 DIDs seen by both references, the zkv pilot saw 13,565 (61.55%), and RocksDB
14,414 (65.41%). These are exact membership cohorts, not degree-histogram
estimates. They measure cold-start window overlap, not eventual completeness.

| Private pilot observation | Grouped zkv | Durable RocksDB |
| --- | ---: | ---: |
| Delivered frames | 30,086 | 33,087 |
| Final processing queue | 84.0 MiB | 78.2 MiB |
| Mean collection-index call, including waits | 3.901 ms | 1.810 ms |
| Host-authority share of accumulated frame-stage time | 81.5% | 89.0% |
| Final RSS | 786.6 MiB | 793.2 MiB |

Private observation starts earlier than the external observer, so the table and
reference overlap cover shifted windows. Live arrivals are not identical replay
traces. Neither pilot established steady state. These results do not attribute the
backlog to KV gets: the index measurement includes writes and waiting, while
host-authority work dominates accumulated frame time. Both private consumers had
zero malformed messages, sequence errors, sequence gaps or unexpected close.
The short mode does not run the 32 sampled collection-membership checks.

[Analysis](zkv-load/grouped-live/paired-smoke/analysis.json),
[exact cohort and transport intervals](zkv-load/grouped-live/paired-smoke/comparison.json),
[raw evidence](zkv-load/grouped-live/paired-smoke).
A ten-minute matched run follows to distinguish startup backlog from sustained growth.

### Shared authority-resolver limit

The source fixes the inline host-authority pool at four resolvers
(`src/internal/validator.zig`, `host_resolver_pool_size`). New identities or a
changed incoming host require an authority decision before validation/indexing;
frame workers wait for a slot when all four are occupied. The existing counters
separate slot waiting from resolver-held decision time.

![Cold-start frame-worker time](zkv-load/grouped-live/paired-smoke/authority.svg)

Over the private smoke intervals, grouped zkv accumulated 995.36 worker-seconds
waiting for a slot and 452.90 seconds in resolver-held decisions across 13,482
network checks. RocksDB accumulated 1,147.54 and 454.24 seconds across 14,229 checks.
Dividing resolver-held time by each approximately 119-second measured interval
estimates 3.80 / 3.81 occupied resolvers out of four; slot waiting corresponds to
8.36 / 9.63 blocked frame workers. These are elapsed-time equivalents, not CPU
utilization or exact instantaneous occupancy; completion counters have boundary
effects for calls spanning the sample interval. Resolver-held time also includes
the authority decision after resolution, rather than isolated HTTP time.

This is evidence of a shared cold-start concurrency limit. It does not establish
that four slots limit warmed steady state, nor that increasing the pool safely
improves capacity. The live run remains unchanged to measure warming first.
Collection-index work still differs, but does not account for most elapsed worker
time in this smoke. No zkv or zeldi runtime change is needed for this diagnosis.

## Ten-minute paired external-observer run

All four evaluator connections stayed up for 600 seconds with null terminal
errors. Both pilots completed their private 600-second windows, delivered without
malformed messages, sequence gaps/reversals or unexpected disconnects, and passed
all 32 sampled fresh collection-membership checks. RAM/disk replay remained off.
Both pilots and the observer were deleted; absence was verified for all three.
Production zlay and zeldi were untouched.

| Measurement | Grouped zkv | Durable RocksDB |
| --- | ---: | ---: |
| Private consumer frames | 309,924 | 293,526 |
| Exact reference-agreement DID coverage | 95.72% | 91.19% |
| Final-minute consumer delivery | 586.5/s | 541.5/s |
| Final queue | 4.02 MiB | 5.54 MiB |
| Maximum queue in final 120 seconds | 6.10 MiB | 5.96 MiB |
| Mean collection-index call, including waits | 6.572 ms | 8.760 ms |
| Final-minute relay CPU | 0.511 cores | 0.506 cores |
| Final-minute whole-VM busy CPU | 0.998 cores | 0.998 cores |
| Final RSS | 795.4 MiB | 831.9 MiB |

The common denominator is 63,034 DIDs seen by both references: zkv saw 60,333,
RocksDB 57,481. This is account overlap within the full cold-start-inclusive
observer interval, not exact revision completeness or an eventual-delivery result.
The private metrics and external observer have shifted start times. These are
matched resources and policies, not identical live arrival traces; the result
cannot establish an intrinsic engine speed ranking.

![Pending frame payload](zkv-load/grouped-live/paired-ten-minute/charts/queued_mib.svg)

Both queues declined from approximately 80 MiB near the first private minute to
roughly 4–6 MiB at the end. Resolver-slot waiting fell substantially: in the last
minute its elapsed-time equivalent was 0.55 waiting workers for zkv and 0.40 for
RocksDB, versus about 10.5 in the first minute. The resolver pool no longer
explains most later-stage waiting. Whole-VM CPU was essentially saturated, while
the relay itself used approximately half a core. The remaining CPU includes
PostgreSQL, the private checker and kernel work; this run does not break that
remainder down by process. Index calls include scheduling and write waits, so
these millisecond values do not isolate get/decode cost.

![Private consumer delivery](zkv-load/grouped-live/paired-ten-minute/charts/events_per_second.svg)

Neither pilot passed the existing full steady-state gate. Tail queue slope and
change met its bounds, but logical caches still grew at 1.17 / 1.09 MiB/min, above
the 0.5 MiB/min gate. RSS also changed, including sizable decreases, failing the
range/slope conditions. This is not evidence of unbounded memory, and it is not a
qualified full steady-state result. Defaults allow 250,000 signing-key entries
and 500,000 DID entries; a ten-minute cold start need not fill those caches.

zkv supplied 228 coherent maintenance snapshots out of 600 scrape attempts; missing
snapshots explicitly report unavailable rather than zero. The last 120 seconds
contained 29 snapshots: unflushed segments ranged 19–230, L0 tables 0–4, and active
compaction was observed. Shutdown reported 70,276 changed commits, 70,144 flushed
segments, 10,580 compaction steps, 9,668 log-GC steps, 133 unflushed segments and two
L0 tables. Maintenance ran during measurement; shutdown did not force-drain debt.
The final zkv index occupied 7,126,124 bytes with three grouped SSTs; RocksDB's live
index occupied 36,103,425 bytes. Those live footprints include different WAL/
flush states and inputs and do not replace the equal-data offline space comparison.

[Raw analysis](zkv-load/grouped-live/paired-ten-minute/analysis.json),
[exact cohort and transport](zkv-load/grouped-live/paired-ten-minute/comparison.json),
[steady-state checks](zkv-load/grouped-live/paired-ten-minute/steady-assessment.json),
[maintenance availability and ranges](zkv-load/grouped-live/paired-ten-minute/maintenance-assessment.json).
This run shows functional ten-minute relay operation and similar bounded tail
queues on the tested resources. Warmed capacity, exact revision coverage,
acknowledgment/crash recovery and CPU attribution remain open; the goal stays active.

## Mid-stream process-kill recovery

The existing offline replay harness now supports `--crash-after`. The client
records a subset of revisions actually observed downstream, including their exact
fixture identity. The runner sends SIGKILL after that checkpoint, asserts exit
137 without OOM, and rejects the run if the source reached its explicit final
flush/drain. It then suppresses source re-ingestion on restart using the existing
replay-control completion marker. That marker is outside the database; no event
or index file is repaired or rewritten by the harness.

Reopening must replay every checkpointed revision with matching CAR bytes and
ordered operations, without duplicates or unknown revisions, and return every
checkpointed collection membership. Additional valid events and memberships may
survive: unacknowledged work is allowed to persist. The checkpoint freezes a known
delivered subset; it is not an assertion that the kill occurred at exactly that
frame or that all possible intervening deliveries were recorded.

| Variant | Checkpointed revisions required | Recovered valid revisions | Required collections checked |
| --- | ---: | ---: | ---: |
| Grouped zkv | 2,058 | 2,216 | 409 |
| Legacy zkv | 2,070 | 2,231 | 411 |
| Durable RocksDB | 2,073 | 2,223 | 412 |

All three passed. The same 8,016-frame ZDS file was offered at 600/s, with 16 workers
and a 20-connection PostgreSQL pool, stopping after approximately 2,048 client
receipts. Grouped recovery exercised a grouped SST plus unfinished log work.
The corpus hash and binary hashes are recorded for every case. Recovery counts
and delivery timings are not throughput comparisons: kill points and scheduling
vary, and extra unacknowledged persistence is permitted.

The resources match the earlier offline screen: two relay CPUs/512 MiB, one
PostgreSQL CPU/256 MiB, and a one-CPU/256-MiB client, on an internal-only Docker
network using cached images and `--pull never`. History is enabled here to verify
persisted event replay; the live no-history pilot intentionally has a different
replay contract. This kills only the relay process. PostgreSQL remains up and OS
caches remain intact, so this does not prove power-loss durability, host failure,
or arbitrary crash-position coverage. Delete/tombstone scenarios are also outside
this create/update fixture. No zkv core or zeldi runtime changes were made.

Every case removed and verified absence of its containers, networks and volumes.
The first RocksDB attempt mistakenly selected its normal binary, failed replay
readiness and was cleaned up; its metadata is retained as a setup failure, not a
recovery failure. The corrected binary hash matches the earlier successful
RocksDB replay screen. A separate 2,048-frame ordinary graceful replay/restart
passed after preparing the checkpoint client.

Reproduce from the Zlay worktree with the matching replay-enabled binary:

```sh
python3 scripts/zkv/replay_run.py \
  --binary /path/to/replay-enabled/zlay \
  --corpus /path/to/zds-relay-maintenance.bin \
  --output /tmp/new-recovery-result \
  --count 8016 --rate 600 --workers 16 --db-pool 20 \
  --encoding grouped --crash-after 2048
```

[Raw checkpoint, recovery and cleanup evidence](zkv-load/grouped-live/midstream-recovery).
Each recovery result distinguishes the required checkpoint size from total replayed
frames. Full warmed capacity, exact live revision coverage, power-loss behavior
and per-frame latency remain open; this process-kill test does not complete the goal.

## Paired revision-latency tracing

The existing signed replay path can opt into `--trace`; production builds and the
default replay keep tracing disabled. The producer records the offered schedule,
entry to `Subscriber.acceptFrame`, and that call's return for every DID/revision.
It reuses existing clock reads and writes the submission trace after the timed
final drain. The client timestamps entry to each WebSocket message callback before
CBOR decoding, then retains the ordinary content, membership and restart oracles.

Both endpoints use Linux `CLOCK_MONOTONIC`, with nanoseconds serialized as decimal
strings. The analysis rejects mismatched boot IDs, missing/different time-namespace
offsets, duplicate/missing revision keys, incomplete recovery, differing workload
or resource settings, and negative ingress-to-receipt latency. The 64-frame
calibration first exposed empty positional `/proc` reads; those traces were
rejected. Bounded streaming reads fixed metadata collection, and the corrected
calibration passed clock matching, delivery, membership, restart and cleanup.

Clock selection is checked against the pinned sources: zio 0.19
`src/os/time.zig` maps `.awake` to `CLOCK_MONOTONIC` on Linux;
[Node 24.22.1](https://github.com/nodejs/node/blob/v24.22.1/src/node_process_methods.cc)
uses `uv_hrtime` for `process.hrtime.bigint`, and
[libuv 1.52.1's public timer](https://github.com/libuv/libuv/blob/v1.52.1/src/unix/core.c)
selects precise time, implemented with
[Linux CLOCK_MONOTONIC](https://github.com/libuv/libuv/blob/v1.52.1/src/unix/linux.c).

Two rotated rounds used the identical 8,016-frame ZDS file at 600/s, 16 frame
workers and 20 DB connections. The order was grouped/RocksDB/legacy, then
legacy/RocksDB/grouped. Every case passed exact revision/CAR/operation checks,
all 1,601 collections, graceful restart and resource cleanup. Containers use the
same offline resource caps and internal-only network as the earlier screen.

| Variant | Ingress-to-receipt p50, trials 1 / 2 | Ingress-to-receipt p99, trials 1 / 2 | Offered-schedule-to-receipt p99, trials 1 / 2 |
| --- | ---: | ---: | ---: |
| Grouped zkv | 63.06 / 65.47 ms | 379.05 / 571.12 ms | 380.49 / 664.87 ms |
| Legacy zkv | 75.53 / 70.71 ms | 624.06 / 583.31 ms | 882.68 / 584.99 ms |
| RocksDB, synchronous index | 71.83 / 57.73 ms | 686.95 / 517.90 ms | 1,515.52 / 524.20 ms |

Percentiles use nearest rank. These are per-revision pipeline/transport latencies,
not KV gets or a durability acknowledgement. Schedule-based latency includes
producer backpressure instead of hiding it by starting each measurement only
when the producer manages to submit. The first RocksDB trial illustrates why
that matters: ingress p99 is 687 ms, but scheduled-demand p99 is 1,516 ms. The
per-revision paired differences are computed from matching keys across runs,
not by subtracting independently computed percentiles.

Trial variability is substantial; there is no stable engine latency ranking.
This finite, small-identity workload does not establish warmed live capacity.
Trace timestamping and allocation remain part of the instrumented work; a
separate untraced 8,016-frame correctness screen passed, but no tight tracing-
overhead bound is claimed.

The shared relay code has two relevant timers: a 100 ms event-file flush loop and
100 ms idle polling in each consumer's write loop. The consumer already signals
a condition on enqueue, but the idle writer currently sleeps instead of waiting
on that condition. These are plausible shared latency contributors; an isolated
polling experiment follows before changing any production implementation.

![Per-revision receipt latency and the polling probe](zkv-load/grouped-live/revision-latency/comparison.svg)

### Consumer wakeup probes

A detached throwaway worktree changed only the consumer's idle sleep from 100 ms
to 1 ms, leaving grouped zkv unchanged. Two runs retained every correctness and
restart check. Median ingress-to-receipt latency fell from 63.06 / 65.47 ms to
10.16 / 4.07 ms. The probe's p99s were 781.31 / 104.61 ms; tails did not improve
consistently. This is an attribution experiment, not a proposed tighter-polling
implementation. The exact one-line patch is retained with the evidence.

The background event flusher also has a 100 ms interval, but `frame_worker` calls
`dp.flush()` after each frame. The timer alone therefore does not impose a 100 ms
floor on this path. The polling ablation supports a shared consumer-wakeup
contribution to median latency; it does not explain all tail variation.

Zig 0.17 provides `Io.Condition.waitTimeout`; the pinned zio 0.19 bridge implements
its futex timeout. The baseline comment claiming that no timed wait exists is
stale. A separate prototype replaces the sleep with a notified condition wait,
retaining the same 100 ms timeout for periodic keepalive checks. Cancellation
still runs queue/staging cleanup and socket interruption. It creates no new
keepalive task and changes no validation, index, event-write or replay policy.

| Timed-notification prototype | Grouped zkv, trials 1 / 2 | RocksDB, trials 1 / 2 |
| --- | ---: | ---: |
| Ingress-to-receipt median | 7.59 / 8.32 ms | 6.79 / 4.52 ms |
| Ingress-to-receipt p99 | 523.49 / 1,134.93 ms | 660.38 / 428.61 ms |
| Completion through final event-file write | 13.684 / 14.144 s | 13.568 / 13.615 s |
| Relay CPU, including oracle readback | 5.71 / 5.26 s | 4.06 / 4.89 s |

All four prototype runs passed the 8,016-revision content oracle, all 1,601
collections, graceful restart and cleanup. However, baseline relay CPU was
4.13 / 2.78 seconds for grouped zkv and 3.41 / 3.37 for RocksDB, with roughly
13.36-second completion. The prototype uses more measured CPU and sometimes
completes later; its overall performance is not an established improvement.
CPU includes ingestion and the subsequent index-oracle readback, not just the
writer. The cause of that added cost and the variable tails remains unisolated.

The functional prototype is checkpointed separately as Zlay
`codex/consumer-notification-prototype` (`21ab2de`) and RocksDB
`codex/rocks-consumer-notification-prototype` (`7305bed`). It is **not promoted**
into either benchmark pilot branch or production. The 1 ms polling probe is also
not promoted. Neither changes core zkv or zeldi.

The remaining shared-Zlay asks are an efficient notified writer that preserves
keepalive/close/slow-consumer behavior without a CPU or throughput regression,
and an explicit event-file durability contract. If the contract requires
power-loss durability, file synchronization and rotation/directory ordering must
precede the advertised durable watermark; the current positional-write watermark
does not supply that guarantee. No engine read-check or validation weakening is
justified by these latency measurements.

[Raw and summarized traces](zkv-load/grouped-live/revision-latency/summary.json),
[paired differences, first round](zkv-load/grouped-live/revision-latency/paired-1.json),
[paired differences, reversed round](zkv-load/grouped-live/revision-latency/paired-2.json),
[polling-only patch](zkv-load/grouped-live/revision-latency/consumer-poll-probe.patch).
Compressed traces remain directly readable by `scripts/zkv/replay_latency.py`.