bench(clob): read-path contention — Arc<Mutex<Book>> vs ArcSwap#2
Open
psyto wants to merge 2 commits into
Open
bench(clob): read-path contention — Arc<Mutex<Book>> vs ArcSwap#2psyto wants to merge 2 commits into
psyto wants to merge 2 commits into
Conversation
Lead with the sharp, star-proven hook (openhl = a Hyperliquid-shape perp DEX as its own Reth L1, 590 tests, read-and-run) instead of the abstract 'DeFi Kit' framing. openhl is the flagship reference implementation, princeps the second, the crates/ kit the shared layer behind them — positioned the way Reth ships (one repo, reusable crates, binaries on top). Content (structure/layer rules/stack/builds) unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reproduces the openhl read path (read_best_bid precompile locks the shared Arc<Mutex<Book>> the block-builder also locks) and measures reader tail latency under a concurrent writer. On this machine: Mutex read p99 ~330us / p99.9 ~6.5ms / max ~55ms, vs ArcSwap p99 ~42ns — same p50 (~41ns), so the mean/median hides the contention cliff entirely. Writer-side tradeoff: ArcSwap clones the whole Book per published version. Run: cargo bench -p rdk-clob --bench read_contention. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
A runnable benchmark of the openhl CLOB read path: the
read_best_bidprecompile locks the sharedArc<Mutex<Book>>that the block-builder also locks to apply orders. Measures what a reader feels while a writer is busy.Result (this machine, writer flat-out, 200k reads, depth 500/side)
Arc<Mutex<Book>>ArcSwap<Book>Same p50 — the mean/median hide the contention cliff entirely. Under a busy writer the Mutex reader blocks for milliseconds; ArcSwap stays flat. Tradeoff: ArcSwap clones the whole
Bookper published version (cost moves to the write side).Honest scope: the writer runs flat-out, so this shows the shape of the cliff (a stress upper bound), not a production p99 — and p99/p99.9 are the robust signal;
maxcan include OS scheduling noise.Run it:
cargo bench -p rdk-clob --bench read_contentionAdds
arc-swapas a dev-dependency; no library change.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
🤖 Generated with Claude Code