1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# zlay collection index on zkv
The current decision and revised measurements are in the [audit report](zkv-zlay-audit.md).
The observations below describe the initial prototype and are retained as history.
The pilot replaces the collection index only. The relay event log and
Postgres are outside this experiment. All workloads used local scratch
directories and synthetic DIDs. The follow-up
[write-path investigation](zkv-diagnostics.md) also replays a finite, already
captured atproto-bench fixture. No relay was started, no upstream was
queried, and no production or heavypad resources were used.
## build and footprint
Zig 0.17.0 on an Apple M5 Pro. Linux x86-64 GNU target, zio, ReleaseSafe.
The first build in each worktree reused downloaded packages and the
host Zig global cache. The RocksDB build overlapped with some native
pilot compilation. Treat wall times as first observations.
| Build | First build wall time | ELF file bytes | ELF loadable file bytes |
|---|---:|---:|---:|
| RocksDB at f3346e9 | 160.47 s | 165,469,368 | 15,193,404 |
| Initial zkv port | 42.14 s | 19,017,680 | 4,192,972 |
| zkv with frame and page batches | — | 19,037,624 | 4,197,532 |
Loadable bytes sum ELF PT_LOAD file sizes. They are neither stripped
artifact size nor resident memory. The workload processes used about
12.5 MiB peak RSS with RocksDB and 5.7–6.4 MiB with zkv. These are
index-only processes, separate from the relay binary measurement.
## offline index workload
The benchmark inserts 8,192 pairs across 4,096 DIDs and two collections,
repeats 4,096 existing pairs, verifies 3,000 cursor pages of 100 DIDs,
and removes all pairs for 512 DIDs. It checks the reverse index for
every DID afterward. Each row is the median of three sequential
passes, in microseconds per listed operation. In batch mode the add
and duplicate columns are amortized per pair. The delete workload
still removes one DID per call.
| Variant | New pair | Duplicate pair | Page of 100 | Remove all for one DID |
|---|---:|---:|---:|---:|
| RocksDB, default WAL | 4.98 | 5.48 | 19.03 | 11.05 |
| RocksDB, synced WAL | 36.98 | 37.78 | 18.64 | 42.98 |
| zkv, one commit per pair | 464.77 | 454.67 | 7.16 | 453.05 |
| zkv, duplicate elision | 461.44 | 1.04 | 5.11 | 449.98 |
| RocksDB, default WAL, batch 64 | 1.41 | 3.01 | 19.01 | 11.17 |
| RocksDB, synced WAL, batch 64 | 2.21 | 3.90 | 18.82 | 42.51 |
| zkv, batch 64 and duplicate elision | 8.99 | 1.10 | 4.72 | 489.24 |
The current zlay RocksDB binding leaves sync disabled. The synced
control turns it on. zkv uses its standard DirStore commit and
explicit maintenance after 256 unflushed segments or 4 MiB. The
engines have different publication and sync paths. Batch boundaries
match in the 64-pair runs. The zkv duplicate check is intentional
application behavior and skips writes only when both index keys exist.
One short concurrent test starts 1,000 verified page reads and 1,024
single-pair writes together. The median per-run scan p99 was 13.0 µs
for zkv, 21.5 µs for default RocksDB and 25.3 µs for synced RocksDB.
Write p99 was 555 µs, 9.5 µs and 51.7 µs respectively. The loops run
at their own speeds and can finish at different times. This is a
contention smoke test, with a fixed arrival-rate test still needed
to characterize backlog and maintenance tails.
## edge cases and decision
The pilot uses two key prefixes in one database and commits both
directions together. It rejects an existing RocksDB directory.
Tests cover cursor paging when one DID is a prefix of another,
idempotent writes, concurrent producers, deletion, maintenance and
reopen, and discarding a page or replacement after an invalid key.
Backfill now commits a page before advancing its Postgres cursor.
Resync replaces all collections for a DID in one batch.
Keep production on RocksDB. The smaller build and fast cursor reads
justify the offline pilot. The current zkv integration still puts
one file publication per novel live pair on the critical path when a
frame contributes one pair. The small synthetic data set and coarse
mutex do not establish headroom for a live relay.
Before considering a rollout:
1. **zlay:** route live producers through a bounded index owner and
coalesce writes across frames without losing acknowledgment or
ordering. Keep duplicate elision, page batches, and atomic resync
in the adapter. Replay a bounded local fixture at fixed arrival
rates and measure relay lag, queue depth, and read/write tails
through maintenance. Include long scans and tombstone bursts.
The pilot uses the threaded pool I/O for the index and its mutex.
Test executor stalls with the zio relay path before sharing it
with live ingestion or API fibers.
2. **zkv:** measure the local commit path by phase. Evaluate an
append-and-sync local journal or group-commit adapter only if
batching still misses zlay's latency or throughput target.
Preserve acknowledged-batch recovery and fencing. Avoid changing
default object-store semantics for this integration.
3. **zkv:** add local crash coverage around file publication, including
the first commit into a newly created directory and an ambiguous
failure after linking a segment. DirStore syncs the staged file and
its immediate parent, so the ordering of newly created parent
directories deserves explicit validation.
4. **zkv:** verify a local read-view contract before replacing the
coarse mutex. Can independent readers see a well-defined committed
generation while maintenance runs, and what happens when collection
races a scan? If the existing refresh and retry contract cannot
serve the API, consider a pinned read view or bounded retention.
5. **zlay:** validate migration from an offline export or a rebuild
with generation-specific progress. A new index must not inherit
Postgres backfill cursors that describe the old index. Verify both
directions, remove/recreate ordering, and restart after kill
during commit or maintenance. Keep a separate directory and a
RocksDB rollback path.
Stop if bounded batching and explicit recovery cannot meet the same
service contract without changing zkv's durability or shifting
unbounded work into zlay's relay threads.
## reproduce
The zkv dependency is the sibling checkout at `eca4fd1`. The RocksDB
benchmark lives on `codex/zkv-pilot`. The zkv pilot is
`codex/zlay-zkv`. For the first two zkv variants, build at
`cbceb11` and `d2ea8bc` respectively.
```sh
zig build -Doptimize=ReleaseSafe -Dbackend=zio -Dtarget=x86_64-linux-gnu
zig build index-bench -Doptimize=ReleaseSafe
scratch=$(mktemp -d)
mkdir "$scratch/index"
zig-out/bin/index-bench "$scratch/index" --batch64 --mixed
```
Use a fresh scratch directory per invocation. Add `--sync` to the
RocksDB driver for the synced WAL control. Omit `--batch64` for
single-pair writes and `--mixed` for the single-threaded trace.
[Single-pair samples](zkv-pilot-single.csv) · [Batch samples](zkv-pilot-batch.csv) · [Concurrent samples](zkv-pilot-mixed.csv)