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

zat.dev/zlay

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

0
0
136 lines · 7.4 KB Raw History
# Offline relay qualification

The paired pilot passes real PDS ingestion, signature/diff verification,
collection indexing, event persistence, downstream delivery and restart checks
with bounded zkv maintenance enabled. It does **not** establish relay-scale
capacity or storage latency parity. The PDS generator and shared relay timers
dominate parts of this test.

## Paired measurements

Two runs use the same private signed PDS stream for both engines. Each has 256
writes to existing DID/collection pairs and 1,280 novel pairs, offered at 10
commits/s, with concurrent collection queries. The second reverses phase order.
All measured commits were signature/diff validated and delivered once; the
harness compares record CIDs, revisions and actual CAR bytes against the source.
Both engines reopen, verify all 1,281 measured collections and replay 32 commits
by cursor with matching CAR hashes.

RocksDB uses synchronous WAL writes; production's default is asynchronous.
zkv uses the bounded pilot profile: 256 log segments before flush, 64 KiB
compaction steps, eight log names per GC step, background table writes, zero
batching delay, batch limit 16 and a page-owner queue of 16.

| Run / phase | Delivery p99, zkv / RocksDB | Query p99, zkv / RocksDB |
|---|---:|---:|
| First / existing | 1,571.8 / 1,658.0 ms | 12.85 / 9.34 ms |
| First / novel | 4,795.9 / 4,687.0 ms | 16.65 / 15.17 ms |
| Reverse / existing | 161.8 / 173.1 ms | 8.12 / 6.12 ms |
| Reverse / novel | 310.4 / 268.0 ms | 6.02 / 5.28 ms |

Delivery is timed from submission to the PDS through receipt by a downstream
WebSocket client. Queries return two fixture repos, not a 1,000-row page.
The first run has shared multi-second stalls and generator lateness up to 3.54
seconds in the novel phase. The reverse run stays within 13 ms of schedule.
Report both: selecting only the cleaner run would hide substantial host/PDS
variation. These are local observations, not an isolated-machine study.

![Local relay comparison](zkv-load/offline-relay/comparison.svg)

Subtracting two engines' p99s is not a paired latency measurement. The reverse
run records timestamps for each identical commit: novel-pair `zkv receipt minus
RocksDB receipt` has median -6.1 ms and p99 +92.0 ms. This includes independent
consumer polling phases. Zlay sleeps for 100 ms on an empty consumer queue and
flushes its event log every 100 ms; broadcast waits for the committed watermark.
Even paired downstream timing therefore cannot isolate index execution cost.
No shared timers were changed to favor the pilot.

| Relay-container cost | zkv | RocksDB |
|---|---:|---:|
| Stripped Linux arm64 binary | 3,654,440 bytes | 13,516,920 bytes |
| CPU, first run | 7.81 s | 7.48 s |
| CPU, reverse run | 5.21 s | 4.91 s |
| Cgroup peak memory, first / reverse | 31.96 / 31.93 MiB | 31.45 / 36.85 MiB |

CPU deltas cover warmup, both load phases and concurrent queries/metrics,
excluding subsequent verification. Peak memory is whole-container memory,
including charged cache, not process RSS. PostgreSQL and PDS costs are excluded.
Raw cgroup device-I/O counters include executable faults, event files and
metadata; they are not index cache-miss measurements. Build durations were not
recorded as a controlled cold-build comparison.

zkv flushes 1,280 log segments in each run, takes eight compaction steps and
164-165 GC steps, and ends with one L0 table and 2-5 unflushed segments. The
`compactions` diagnostic remains zero because it counts the synchronous full
compaction path; `compaction_steps` counts this stepped path. This is bounded
remaining log state, not zero maintenance debt. First-run pool backpressure
counts are zkv 0 / RocksDB 2; reverse-run counts are both zero.

The initial 50/s attempt is retained as `generator-limited.jsonl`: 2,048
existing-pair writes took about 100 seconds and scheduling fell almost 60 seconds
behind. It was stopped rather than presented as 50/s throughput. Cold PostgreSQL
startup also exposed a harness race: Unix-socket readiness accepted its temporary
initialization server before TCP opened. The consumer now probes TCP.

## Sources and isolation

Raw reports, binary hashes, reverse-run per-commit timings and restart oracle:
[zkv-load/offline-relay](zkv-load/offline-relay). Binaries use Zig 0.17.0,
ReleaseSafe, zio and libc allocation on native Linux arm64 under OrbStack
(18 vCPUs, 16.8 GB VM memory). The host also runs unrelated workloads.
Source-equivalent relay revisions are zkv `66cc23a` and RocksDB `8a16364`;
the final strip option was uncommitted when these recorded binaries were built.
zkv's dependency is `zkv-read-prefix` at `221c87c`. No core zkv or zeldi source
changed, and production checkouts were untouched.

Atmosphere in a Box is pinned at `c91a650`, using its cached stable PDS, private
PLC, DNS and verified HTTPS. The provider project was `zkv-zlay-offline`, network
`zkv-zlay-offline_atmosinabox`, inspected as internal, subnet `172.30.247.0/24`,
DNS `172.30.247.3`, HTTPS gateway `172.30.247.2`. Endpoints were
`https://plc.atmosbox.test` and `https://pds1.atmosbox.test`.

The independent consumer owns two relays, separate PostgreSQL and event/index
volumes, and a fixture client. It needs no canonical HTTPS route for the relays:
the client uses the private network. Relays receive only the exported public CA,
read only, one explicit private-PDS exception and a private PLC endpoint. Only
the fixture client receives seeded account credentials. Public defaults and
signature/diff verification remain enabled. Warmup waits for both signing keys
and observed verified commits before measurement.

No public upstream, image pulls, host ports, host CA installation, host DNS
changes, heavypad or Fly work were involved. Both consumer runs remove their
containers and volumes. The provider was destroyed afterward; filtered Docker
inventories confirmed all owned containers, networks and volumes absent. Its
private CA remains in the private temporary checkout, as required by its CLI.
Never commit private state, credentials, expanded Compose or failure logs.

## Reproduction and remaining qualification

Create and seed a fresh pinned provider using cached images, inspect its actual
network/CA/DNS, and put those values and a disposable DB password in a private
environment file. Build both binaries with
`-Dbackend=zio -Dtarget=aarch64-linux-gnu -Doptimize=ReleaseSafe -Dstrip=true`.

```sh
uv run --no-project python scripts/zkv/offline_run.py \
  --env-file FILE --output DIRECTORY --count 1280 --rate 10
```

Add `--reverse` for the other phase order. The runner owns consumer startup,
resource snapshots, restart verification and volume cleanup. Provider cleanup
remains the caller's responsibility. Regenerate the figure from both saved run
directories:

```sh
uv run --no-project --with matplotlib python scripts/zkv/offline_chart.py \
  docs/measurements/storage/zkv-load/offline-relay docs/measurements/storage/zkv-load/offline-relay/comparison.svg
```

The next capacity test needs finite signed-frame replay through the actual
processing queue and persistence path, without PDS HTTP writes as the bottleneck.
This two-DID, many-collection fixture also needs a complementary many-DID
workload. Warm-cache tests do not qualify cold/evicted key validation: the shared
[fail-open issue](../../architecture/car-verification-review-2026-09-20.md) remains out of scope here.
Power-loss recovery, disk-full behavior and controlled cold-build cost remain
open. None is evidence against zkv, and none should be waived to claim a
production replacement.