feat(xmtp_db): disk-latency benchmark for fresh-DB creation#3824
Open
mkysel wants to merge 2 commits into
Open
feat(xmtp_db): disk-latency benchmark for fresh-DB creation#3824mkysel wants to merge 2 commits into
mkysel wants to merge 2 commits into
Conversation
|
Claude encountered an error —— View job PR Review in Progress
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3824 +/- ##
==========================================
+ Coverage 84.70% 84.72% +0.01%
==========================================
Files 409 409
Lines 60901 60901
==========================================
+ Hits 51588 51597 +9
+ Misses 9313 9304 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add a WAL-compatible SQLite VFS shim (`latency_vfs`, behind a new `bench` feature, native-only) that wraps the platform default VFS and injects a configurable per-op delay on xSync/xWrite/xRead, plus op counters. Add a Criterion bench (`db_init_latency`) that sweeps injected latency over `EncryptedMessageStore` creation — the ~63 Diesel migrations — to model network-attached storage (e.g. EFS) and quantify how per-account libxmtp init scales with disk latency. Measured: a fresh store does ~768 writes but only ~6 fsyncs, so write-op round-trips — not fsync — dominate on high-latency storage (write+sync 10ms/op -> ~10.5s vs fsync-only -> ~140ms). Reproduces the ~4s Fargate/EFS agent-init cost tracked in CON-245. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
170bc2c to
bc55db9
Compare
Contributor
ApprovabilityVerdict: Approved This PR adds benchmark infrastructure behind a feature flag ( You can customize Macroscope's approvability policy. Learn more. |
insipx
approved these changes
Jul 7, 2026
Extend the latency VFS to time each delegated real call per op type (open/sync/truncate/write/close/…) and expose op_times(), so a fresh-store creation can be attributed to op types on real storage where the injected model can't. Add an XMTP_BENCH_DIR override so the bench/tests can target a real mount (Archil/EFS/EBS) at zero injected latency, plus two #[cfg(test)] diagnostics: per-migration write attribution and per-op-type timing. On a real Archil mount, metadata + fsync dominate (sync/open/delete/shm/ truncate ~78%), not the 768 writes (~18%) — the opposite of the EFS model. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Dismissing prior approval to re-evaluate f4f7096
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Adds an on-demand benchmark that measures libxmtp's fresh-DB creation (the ~63 Diesel migrations run by
EncryptedMessageStore::new→init()) as a function of injected per-op disk / fsync latency, to model network-attached storage (e.g. AWS EFS) and quantify how per-account client init scales with it.Two pieces:
crates/xmtp_db/src/latency_vfs.rs— a WAL-compatible SQLite VFS shim (in the style of SQLite'svfstrace.c). It wraps the platform default VFS, delegates every VFS/file method to it, and only adds a configurablethread::sleeponxSync/xWrite/xRead, plus per-op counters. Scoped by filename so only the target DB (and its-wal/-shm/-journalsiblings) is slowed. Because SQLCipher is a codec layered above the pager, real I/O still flows through this VFS, so the numbers are representative of the encrypted store. Gated behind a newbenchfeature, native-only.crates/xmtp_db/benches/db_init_latency.rs— a Criterion bench sweeping injected latency{0,1,5,10} ms/opover a fresh persistent encrypted store, in two scenarios (fsync_latency= xSync only;write_sync_latency= xWrite+xSync).Run
Result / motivation
A fresh store does ~768 writes but only ~6 fsyncs, so write-op round-trips — not fsync — dominate on high-latency storage:
fsync_latencywrite_sync_latencyAt ~5 ms/op this reproduces the ~4 s Fargate/EFS agent-init cost tracked in Linear CON-245. Takeaway for that work: the lever is getting the 768 migration writes off the per-account hot path (pre-migrated template DB), not reducing fsyncs.
Scope / notes
benchfeature.Client::create) variant was intentionally left out: it needs a live local backend, and its DB portion is exactly what this DB-layer bench already isolates.criterionas anxmtp_dbdev-dep, socargo hakari generate/ a fulljust lintpass may be needed before marking ready.Note
Add disk-latency benchmark for
EncryptedMessageStoreinitialization inxmtp_dbdb_init_latency(gated by a newbenchfeature) that measuresEncryptedMessageStorecreation time across configurable per-op I/O delays (0, 1, 5, 10ms).xRead,xWrite, andxSync, injects nanosecond-level delays, counts ops, and scopes injection to files matching a configurable token.register()replaces the process-wide default SQLite VFS; this is only reachable under thebenchfeature on native targets.Changes since #3824 opened
latency_vfsmodule with per-operation timing tracking across all SQLite VFS operations [f4f7096]Macroscope summarized bc55db9.