Skip to content

perf(id): #557 many-worlds profiler, profile, and the worker-parking fix (p99 220,673 → 843 ms in-venue) - #12499

Merged
dezren39 merged 4 commits into
mainfrom
felix/557-p99-profile
Nov 22, 2026
Merged

dezren39 merged 4 commits into
mainfrom
felix/557-p99-profile

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

The #557 profile-and-fix campaign: a reusable profiler on the F11.8 harness, the measured cost breakdown, and the fix for the dominant cost. (Per the issue's 2026-11-21 decision: profile first, then one PR per cost with before/after numbers. This PR carries the profiler + report + the fix for cost 1, the only cost with a clean code fix in this venue.)

Profiler (3e2607a)

The F11.8 many_worlds bench is now parameterized (ID_BENCH_MW_IDLE_WORLDS / ID_BENCH_MW_ACTIVE_WORLDS / ID_BENCH_MW_EVENTS_PER_SECOND / ID_BENCH_MW_DURATION_SECS; defaults are the committed full size) and prints a profile many_worlds … attribution line per run: journal-append and command histograms merged across the active worlds, deepest actor queue depth, checkpoints during load. Producing command is documented in the BASELINES.md campaign section.

Profile (sandbox venue: full 1,000 idle / 100 active, 20 ev/s, 10 s)

Baseline: p50 = 109,337.796 ms, p99 = 220,672.952 ms, 86.0 completed/s. (Sandbox numbers are this machine's own — ~1.5-core quota, btrfs — not comparable to the reference laptop's 5,650.792 ms; the breakdown and the before/after chain are what transfer.)

  1. Tokio worker parking on the blocking journal rendezvous — ~99.9% of p99. JournalWriter::append waited on a std mpsc rendezvous while the writer thread wrote+fsynced; actors are tokio tasks, so each append parked a shared worker for the full sync. Throughput measured 86.0/s vs the ceiling 4 workers ÷ 46.5 ms ≈ 87/s, against 2,000/s offered — the p99 is backlog behind that ceiling.
  2. Per-command sync_data — 46.5 ms mean, ~100% of command service time. A lone append+sync costs ~42 ms on this storage even at 4 active worlds.
  3. Group commit never engages (appends-per-sync stays 1.0; one sequential producer per world, so batching would have to coalesce across worlds at the device).

Fix 1 (e55fe23) — cost 1

recv_writer_reply in world_store.rs runs the writer-reply wait under tokio::task::block_in_place on multi-thread runtimes, so the runtime replaces the parked worker; direct wait elsewhere (plain threads, spawn_blocking, current-thread test runtimes). No durability or ordering change: an append is still acknowledged only after its write+sync completes.

Same profiler, same configuration: p50 109,337.796 → 544.287 ms, p99 220,672.952 → 842.887 ms, 86.0 → 1,836.3 completed/s.

Fix 2 — evaluated and rejected, not in this PR

Cross-world group commit via syncfs: at quick size the journal-append mean regressed 41.7 → 147.4 ms and the run failed in the checkpoint phase — in this venue syncfs flushes the entire shared filesystem, build artifacts included. Rejected on the measurement; the design only pays on a filesystem dedicated to world data. Recorded in the report.

Tests

cargo test -p id-worlds --lib: 830 passed, 39 failed — all 39 are iroh *_net connect timeouts, proven pre-existing by running the same tests on a pristine origin/main worktree (sampled 3/3 fail identically there; also filed as #12488). Journal/actor/hub/session suites pass; the bench's checkpoint/evict/reopen verification passes 100/100/100.

Residual

The 50 ms target is not met in this venue and this PR does not claim it: after Fix 1 the system runs at ~92% of its service ceiling, and the venue's lone fdatasync (~42 ms) is already most of the budget. The deciding measurement needs hardware whose sync latency leaves headroom — on the reference laptop (lone append 5.2 ms) Fix 1 alone lifts the worker ceiling to the device limit and puts per-world service in the ~6 ms class (inference from measured components, labeled as such in the report). The acceptance criterion stays open until a recorded run shows target_met=true.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Journal writer waits now avoid blocking Tokio worker threads on multi-thread runtimes, helping maintain responsiveness during journal operations.
  • Benchmarking
    • Many-worlds benchmarks can be configured with environment variables and now report aggregate journal and command latency, actor queue depth, and checkpoints during load.
  • Documentation
    • Added a profiling report with baseline and follow-up measurements, findings, and remaining latency status.

felix added 3 commits November 22, 2026 08:18
…actor-metrics attribution line (#557)

The F11.8 many_worlds workload now doubles as the #557 profiler:

- ManyWorldsConfig::full() reads ID_BENCH_MW_IDLE_WORLDS,
  ID_BENCH_MW_ACTIVE_WORLDS, ID_BENCH_MW_EVENTS_PER_SECOND and
  ID_BENCH_MW_DURATION_SECS (defaults are the committed full size:
  1,000 idle / 100 active / 20 ev/s / 10 s), so one binary sweeps
  scale without recompiling. checkpoint_every follows the tick
  count (ticks + 2), preserving 202/22 for the full/quick configs.
- After the timed load (before the checkpoint triggers), the bench
  aggregates the active worlds' actor metrics and prints one
  'profile many_worlds ...' line: journal-append and command
  latency histograms merged across worlds (exact means from
  sum/count, bucket-upper-bound percentiles), deepest actor queue
  depth, and checkpoints completed during the load. This attributes
  a run's latency to the journal sync vs the rest of command
  handling with no external tooling.

Harness only; no production code changes.
…ezvous (#557)

Cost 1 of the #557 many-worlds profile. JournalWriter::append and
::replace waited on a std mpsc rendezvous while the writer thread
wrote and fsynced. World actors are tokio::spawn tasks, so every
append parked one shared runtime worker for the full sync latency:
with W workers the whole hub caps at W appends per sync latency.
The sandbox profile measured the ceiling exactly — 4 workers /
46.5 ms mean append = 87 appends/s against 2,000 offered, and the
backlog was ~all of the p99 deadline lateness.

recv_writer_reply now runs the wait under tokio::task::block_in_place
on multi-thread runtimes, so the runtime replaces the parked worker;
everywhere else (plain threads, spawn_blocking, current-thread test
runtimes) the wait is direct, as before. No durability or ordering
change: an append is still acknowledged only after its write+sync
completes on the writer thread.

Same profiler, same full configuration (1,000 idle / 100 active /
20 ev/s / 10 s, sandbox, TMPDIR on btrfs):
  before: p50=109337.796 ms, p99=220672.952 ms, 86.0 completed/s
  after:  p50=544.287 ms,    p99=842.887 ms,    1836.3 completed/s

Tests: cargo test -p id-worlds --lib — 830 passed; the 39 failures
are all iroh *_net connect timeouts (sandbox transport), in modules
this change does not touch; journal/actor/hub/session suites pass.
…andbox)

Appends the 2026-11-22 campaign section to the F11.8 baselines doc:
the producing command, the sandbox environment note, the baseline
profile (p99=220672.952 ms), the top three costs with their shares
of p99 (Tokio worker parking on the journal rendezvous ~99.9%;
per-command sync_data 46.5 ms mean = ~100% of service time; the
#8239 group-commit drain never engaging, queue_depth_max=0), fix
1's before/after (p99 842.887 ms, 1836.3/s), the syncfs group-commit
experiment's rejection in this venue (append mean regressed
41.7 -> 147.4 ms at quick size; syncfs flushes the whole shared
filesystem), and the residual analysis: at a ~42 ms lone fdatasync
the venue itself saturates the 50 ms budget, so the deciding run
belongs on reference-class hardware. baseline.txt/jsonl unchanged
(reference machine class).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T10:39:17.701334Z 1de4219 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The many-worlds benchmark now accepts workload overrides and reports aggregate actor metrics. Journal writer reply waits use block_in_place on multi-thread Tokio runtimes. The profiling report records baseline results, the wait adjustment, and a rejected group-commit experiment; the p99 target remains unmet.

Changes: Many-worlds profiling

Layer / File(s) Summary
Configure workloads and report aggregate metrics
pkgs/id/benches/world_bench.rs, pkgs/id/benches/BASELINES.md
The benchmark reads workload settings from ID_BENCH_MW_* variables and reports aggregate journal-append and command-latency statistics, maximum actor queue depth, and checkpoints during load. The report records the baseline and measured costs.
Adjust journal reply waits and record outcomes
pkgs/id/crates/id-worlds/src/world_store.rs, pkgs/id/benches/BASELINES.md
Journal writer append and replace operations use block_in_place for reply waits on multi-thread Tokio runtimes and wait directly in other contexts. The report records results, the rejected group-commit experiment, and the remaining p99 target status.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • developing-today/code#1387 — Adds the benchmark harness in world_bench.rs, which this PR extends with workload overrides and aggregate metrics.

Suggested reviewers: claude

Merge Risk: Low · up to c1970

This change adjusts how journal writer replies are awaited and adds benchmark profiling knobs. The benchmark can panic when a workload override is set to zero, and its attribution metrics include setup work. Neither affects production behavior, so merge risk is low.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.1)

Clippy execution timed out
Clippy (1.99.1) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

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.

Share

@dezren39
dezren39 merged commit d9dc29a into main Nov 22, 2026
@dezren39
dezren39 deleted the felix/557-p99-profile branch November 22, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant