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

zat.dev/zlay

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

0
0
164 lines · 8.8 KB Raw History

Offline collection-index disk comparison

This experiment compares the real Zlay zkv and RocksDB adapters on identical, locally generated membership operations. It measures the collection index, not PostgreSQL, replay files, container images, or the relay's total disk usage.

Results

For identical two-million-membership contents, zkv retained 1.77 times as much index disk as RocksDB after ingestion and maintenance. This is a real storage density gap, rather than an inference from differently aged production databases.

MeasurementzkvRocksDB
Settled after ingestion269.9 MiB152.5 MiB
Bytes per logical membership141.580.0
Settled after duplicate pass269.9 MiB152.7 MiB
Settled after three churn cycles270.2 MiB153.5 MiB
Largest sampled temporary footprint553.3 MiB365.9 MiB

Both engines passed complete forward scans and reverse-membership presence checks for every generated DID after reopening. The same 1,000-account cohort was deleted and restored three times. zkv's small retained increase mostly plateaued after the first cycle. This does not establish steady state under a larger or changing deletion cohort.

At the final checkpoint, zkv's SSTs occupied 283,281,190 bytes versus RocksDB's 159,216,515 bytes. RocksDB also retained about 1.7 MB of diagnostic logs from repeated reopening. Therefore the density gap persists when diagnostic files are excluded.

Disk growth, retained size, and filesystem writes

The first graph shows capacity consumed by genuinely new memberships. The second holds final logical contents fixed while varying duplicate and deletion history. The third distinguishes lifecycle writes from explicit settling, because physical maintenance operations differ between engines. All byte totals include actual filesystem accounting rather than just encoded input size.

OS-accounted writeszkvRocksDB
Ingestion lifecycle1,699.6 MiB590.3 MiB
Duplicate pass0.012 MiB376.1 MiB
Churn lifecycle137.8 MiB38.0 MiB
Explicit settling across the run0.7 MiB1,245.3 MiB

Lifecycle categories include reopening and associated verification, so background maintenance during verification is counted. Ingestion includes ordinary automatic maintenance; explicit settling is a separate category. These results show both zkv's duplicate-elision benefit and its more expensive initial storage writes. RocksDB's large explicit-settling total reflects this harness repeatedly requesting full-range compaction. It is not a measurement of normal relay write amplification and must not be used to claim a production write-I/O win for zkv.

RocksDB's persisted options show compression=kNoCompression and block_restart_interval=16. zkv's entry.append writes the entire key with a nine-byte header; block.Writer adds a four-byte offset per entry. RocksDB's prefix-compressed table keys are a concrete encoding difference to investigate. This run does not isolate what fraction of the gap comes from that difference, as opposed to other encoding and maintenance choices.

Operationally, this workload needs about 77% more retained index disk with zkv. That does not translate into 77% more total relay cost: PostgreSQL, replay, CPU, memory, storage provisioning, and maintenance headroom remain separate. The sampled peaks also show why provisioning only the settled index size is insufficient. The canary's different asynchronous maintenance schedule needs its own peak-space qualification.

Raw stage measurements, environment and file breakdown, and plot summary accompany the graph. The measured harness source matches the SHA in the metadata; the maintained harness subsequently adds crash-add without changing the measured workload phases.

Workload and controls

  • 1,000,000 deterministic pseudorandom 32-byte DIDs, each in two collections: app.bsky.feed.post and one of 31 secondary collections. This produces 2,000,000 logical memberships and 4,000,000 forward/reverse index entries.
  • Ten growth checkpoints, one complete duplicate pass, then three cycles that remove every thousandth DID and restore it. Each cycle changes 1,000 accounts and 2,000 memberships: a small deletion cohort, not a heavy deletion workload.
  • Identical addCollectionPage calls: up to 4,096 DIDs for the common collection, followed by the corresponding secondary-collection groups. Deletion uses the real removeAll adapter method; restoration uses addCollection.
  • RocksDB has sync_writes=true; zkv's directory store syncs files and parent directories. This matches the intended acknowledged durability boundary; it does not prove identical behavior under power loss.
  • ReleaseSafe, Zig 0.17.0, C allocator, native Linux on heavypad. All input is generated there. No PDS, firehose, R2, or production database participates.
  • Each stage opens and closes the database. Reopened verification scans all collections, checks counts and 64-bit membership checksums, and checks reverse membership for every generated DID, including deleted accounts.

The default synchronous zkv adapter maintenance runs throughout ingestion: 256-segment / 4 MiB flush triggers and ordinary compaction/collection. The live canary instead uses bounded asynchronous maintenance. Consequently, this run isolates adapter storage efficiency but its transient peaks are not a direct measurement of the canary's maintenance schedule.

Explicit settling flushes and drains zkv's eligible compactions and collection; for RocksDB it flushes both column families and runs full-range compaction. These engines expose different maintenance controls. Settled results retain that policy difference; zkv settling does not promise a forced rewrite of every level or removal of every tombstone.

Both adapters receive the same duplicate requests. zkv deliberately elides existing memberships; RocksDB rewrites them. That is an adapter design difference being measured, not an omission from the generated workload.

Measurements

The runner records total database-file lengths, allocated file blocks, file counts, and sampled temporary peaks every 250 ms. Peaks are observed lower bounds, not guaranteed maximum disk requirements. Directory metadata is excluded. Linux child-process block-I/O accounting records reads and writes, including maintenance and filesystem effects; these are not NAND-level device writes. Read accounting from this warm-cache experiment is not a cold-read benchmark.

Timing includes opening/closing and polling overhead in the JSON records; the per-stage logs separately report the timed adapter operations. Other work runs on heavypad, so this experiment's primary conclusions concern space and I/O, not a production throughput ceiling.

The initial calibration used 64-DID chunks and was stopped after discovering excessive synchronous-operation overhead. Its partial database is excluded. Both measured engines use the same corrected 4,096-DID workload.

Crash recovery check

After the space measurements, each million-DID database received another 4,096 DIDs (8,192 memberships) with the same synchronous write guarantees. The harness printed acknowledgement only after all writes completed, then raised SIGKILL before database deinitialization. Both engines reopened and passed full forward scans plus reverse-presence checks for all 1,004,096 DIDs / 2,008,192 memberships. This checks abrupt process death after acknowledgement, not power loss or every possible crash point during compaction. These extra memberships are excluded from the space graphs above.

Raw zkv and RocksDB recovery results are retained. Reproduce with scripts/zkv/space_crash.py BINARY DATABASE EXISTING_DID_COUNT; it deliberately kills the child and adds data to the supplied experiment database.

Reproduction

Build zig build index-space -Doptimize=ReleaseSafe on the zkv canary and RocksDB control branches, then run:

uv run --no-project python scripts/zkv/space_compare.py OUTPUT ZKV_BINARY ROCKS_BINARY --count 1000000

The runner refuses to reuse an engine database directory. --engine zkv and --engine rocks permit sequential runs into the same output directory. Database files remain available for inspection; JSONL records and stage logs are retained.

Validation

Both ReleaseSafe harness builds, all 30 measured stages per engine, and both post-SIGKILL recovery checks passed. The existing zig build test -j2 suite also exited successfully in both source mirrors on heavypad, run through git rebase -x for each new harness commit. No production or Zeldi code changed.