Repository navigation
id(worlds): #557 second pass — write the journal inline instead of via a writer thread - #12552
Merged
Merged
Conversation
added 2 commits
November 22, 2026 12:42
FileJournal handed every append to a dedicated writer thread over a channel and rendezvoused on its reply. The journal's only producer is its owning actor, which reaches it through &mut and cannot have a second append in flight while one waits for durability, so the writer's queue was empty at every dequeue by construction (the same structural reason the actor-side drain reads queue_depth_max=0 in the many-worlds profile): each append paid a channel send, a thread wake, and a rendezvous reply around the same write+sync, plus one thread per world. The journal now owns its File and writes inline through sync_journal_write, which runs the write_all + sync_data under the same block_in_place guard the #557 worker-parking fix established, so no shared Tokio worker parks for the sync. Compaction's writer replace becomes a field assignment. No durability or ordering change: an append is still acknowledged only after the sync that covers its bytes completes.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Open
2 of 3 tasks
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Second-pass review of the many-worlds event path for #557, per the direction to look for any other obvious wins regardless of the 50 ms target. One clean win landed; the rest of the seams were audited and are recorded below with their evidence.
Landed: write the journal inline instead of via a writer thread (ee371a0)
FileJournalhanded every append to a dedicated writer thread over a channel and rendezvoused on its reply. The journal's only producer is its owning actor, which reaches it through&mutand cannot have a second append in flight while one waits for durability — so the writer's queue was empty at every dequeue by construction (the same structural reason the actor-side drain readsqueue_depth_max=0in every profile). Each append paid a channel send, a thread wake, and a rendezvous reply around the same write+sync, plus one thread per world (1,100 threads at bench scale).Now the journal owns its
Fileand writes inline viasync_journal_write, which runs the onewrite_all+ onesync_dataunder the sameblock_in_placeguard the first #557 fix established, so no shared Tokio worker parks for the sync. Compaction's writer-replace becomes a field assignment (ordering already guaranteed by&mut). No durability or ordering change: an append is still acknowledged only after the sync that covers its bytes completes.Before/after (sandbox venue, TMPDIR on btrfs, full 1,000 idle / 100 active, 20 ev/s, 10 s)
a968bf0f0(pair run, load avg 8.5 at start)Verdict: not measurable in this venue. The sandbox is shared, and its load swung widely between runs; latency percentiles moved ±2× with ambient load (in the pair, the wake percentiles doubled while
input_ack_p50stayed flat at ~62–63 ms in both runs), while the mechanism metric — journal append mean — stayed in one band (47.7k–58.4 µs for this change vs 52.7k for the baseline at comparable load). No run shows a regression attributable to the change. The change is landed as a structural simplification — two fewer synchronization hops per append, one fewer thread per world, −105/+31 lines — with durability semantics unchanged; whether neutral-but-simpler is worth merging is the reviewer's call. All runs:queue_depth_max=0, checkpoints/evicted/reopened 100/100/100. The runs are also recorded inpkgs/id/benches/BASELINES.md;baseline.txtis untouched (reference machine class). For reference, the first campaign's post-fix sandbox run measured journal_append_mean 50,473 µs / p99 842.887 ms / 1,836.3 completed/s — the same band.Tests:
cargo test -p id-worlds --lib— 836 passed / 40 failed. 39 failures are the known live-network timeout class filed as #12488 (38 named*_netplusworld_recordspeer-sync "deadline has elapsed"). The one remaining failure,write_lease_entries_require_journal_version_7, is pre-existing ona968bf0f0: the kv provider (PR #12489) movedMAX_JOURNAL_VERSION12 → 13 without updating that test's pin; filed as #12541. Zero failures attributable to this change.cargo fmt -p id-worlds -- --checkis clean for the touched file (pre-existing drift inlib.rs/world/replication.rsleft alone).Seam audit (no change)
write_all+ onesync_data(fdatasync). Nosync_all, no directory sync per append (directory sync appears only in compaction, after the rename). Nothing heavier to remove.append_batchalready concatenates to one write + one sync).Arcshare of the actor's own command sender.serde_json::to_vecper entry is required.persist()additionally builds a second full serialization (journal_entry_line) for the replication broadcast even when it has zero receivers; gating it onreceiver_count()would be safe (late subscribers resync from snapshot; broadcast never replays pre-subscribe appends). Evaluated and rejected as unmeasurable churn: on the post-fix laptop run the whole non-append command path — prepare, guest update, records, this serialization, channel sends — fits inside the difference between command_mean_us=25692 and journal_append_mean_us=25784. Recorded here so a future CPU-bound profile can pick it up.input_ackwaits for the journal sync in both the single and batch paths; that is the documentedWorldJournalcontract ("acknowledged history must never get ahead of durable history"). On the post-fix laptop run, input_ack_p50 = 18.892 ms against journal_append_mean = 25.784 ms — the ack is the sync wait plus scheduling. Any batched/async ack changes durability semantics and is a decision for @dezren39, not a clean win.Refs #557
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.