Skip to content

perf(net): avoid redundant stats drain synchronization - #6293

Merged
kixelated merged 5 commits into
mainfrom
quest/m1/release-perf/stats-report
Oct 22, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m1/release-perf/stats-report

Conversation

@kixelated

@kixelated kixelated commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The session stats drain takes each label's payload mutex twice and uses Arc::get_mut for every live session. The old session-report benchmark omits registered transport wires, hiding the additional connection walk.

Approach

Read payload totals and the empty-live condition under one row guard. Since private SessionTraffic has no weak references, detect its final owner using Arc::strong_count and an Acquire fence paired with the last writer's Arc drop. Preserve per-label bytes, retag cuts, late meters, pruning and lifetime totals.

Register real transport wires in the session-report benchmark and independently sweep labels, sessions per label, and connections per session. Validate fixture wire totals before measuring. Extend the existing concurrent snapshot/retirement test to check monotonic and final per-label payload bytes.

Impact

  • Public API: none.
  • Wire: none. Counter names, serialization, per-label attribution and write-path behavior stay the same.
  • Consumer: moq-stats drains and relay metrics scrapes reuse the same registry.

Alternatives

Deleting per-label bytes was already rejected in the quest. An O(labels) push design would move cost to writes and needs separate planning. Retain the existing safe Wire ownership and lock ordering unless measurements justify a larger change.

Measurements

Three alternating before/after rounds, each with 20 Criterion samples, 0.3 s warmup and 1 s measurement per case. Values below are medians of three per-run medians in microseconds/report at 1,000 labels:

Sessions/label Connections/session Before After
1 0 35.2 29.7
1 1 66.4 60.6
1 4 159.6 154.3
10 0 88.6 52.2
10 1 416.1 388.4
10 4 1361.4 1335.5

The payload-only 10,000-session drain improves 41.1%; including one Wire/session improves 6.6%. The remaining wire-inclusive drain costs about 0.04% of a core at one report/second. The epic now records this accepted O(sessions/connections) feature cost and corrects its earlier estimate, which omitted Wire sampling. The four-connection case improves only 1.9%; its first baseline round was noisy, and the table uses the median across all three rounds.

Reproduce with cargo bench -p moq-net --features fuzz --bench stats -- stats/session-report --sample-size 20 --warm-up-time 0.3 --measurement-time 1 --noplot in the Nix shell. All 18 sweep cases validate their registered wire totals before measurement.

Validation

  • Focused stats tests: 46 passed, including the extended concurrent retirement assertions and existing retag, late-meter and wire accounting tests.
  • All 18 benchmark configurations completed three before and three after rounds; benchmark clippy passed with warnings denied.
  • just ci passed Rust lint/docs/build/WASM/uring checks, quest validation (472 documents), and drill applicability. Its unchanged runner-image build failed because this host denies unshare writing /proc/self/uid_map.
  • The unexecuted gate continuation was run directly: dependency install and markdown/shell/TOML/Nix/Just/workflow lints pass. Selected default Rust suite: 7,979/7,980 passed (58 skipped); the only failure is the reproduced base CLI late-stats readiness issue fixed separately in moq-dev/moq#6290. No duplicate fix is included here. Feature continuation: 511 capture/playback tests passed (13 skipped), 219 CLI playback tests passed (1 skipped).
  • Formatting and git diff --check pass.

Quest

Completes and retires quest/m1/release-perf/stats-report.md. The release-perf epic records the remaining O(live sessions) drain cost as accepted, and its comparison table now marks stats/session-report as accepted instead of linking the retired quest.

Follow-ups

The pre-existing CLI readiness failure is owned by #6290. No duplicate fix or follow-up is included.

(Written by GPT-6)

(Written by Claude Opus 5.5)

@kixelated kixelated changed the title Stats report perf(net): avoid redundant stats drain synchronization Oct 22, 2026
Co-Authored-By: GPT-6 <noreply@openai.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Completed the stats source work and three alternating benchmark rounds. At 10,000 sessions, the payload-only drain falls from 88.6 to 52.2 us/report (-41.1%); including one registered transport Wire/session falls from 416.1 to 388.4 us (-6.6%). Per-label bytes and stats semantics remain, with no public API or wire change. The epic now records the actual wire-inclusive accepted cost, about 0.04% of a core for a once-per-second drain.

Verification: 46 focused stats tests, benchmark clippy, all lints, 472 quest documents, 511 capture/playback tests and 219 CLI playback tests pass. The default suite passes 7,979/7,980; its only failure is the base late-stats readiness issue handled by #6290. just ci also encountered the host's known runner-image user-namespace restriction; remaining checks were continued directly.

Automatic approval review rejected retiring the completed quest via quest rm, treating that cleanup as abandonment. No retry or workaround was attempted. This remains draft solely for the narrow completion-retirement approval under Decisions needed; the accurate quest and references are retained.

(Written by GPT-6)

kixelated and others added 2 commits October 22, 2026 14:04
The stats drain fix is complete; the remaining O(live sessions) cost is
accepted in the release-perf epic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review October 22, 2026 21:06
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T21:09:59.272661Z afa0454 Manual request
ℹ️ 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 Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 974e13f4-1d5c-4b85-89fe-2d9d6da215f6
📥 Commits

Reviewing files that changed from the base of the PR and between 43fc925 and f7a151a.

📒 Files selected for processing: 4
  • quest/m1/release-perf/README.md
  • quest/m1/release-perf/stats-report.md
  • rs/moq-net/benches/stats.rs
  • rs/moq-net/src/stats.rs

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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afa04543ba

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rs/moq-net/src/stats.rs Resolved
The (Presence, bool) return type broke the source needle, so the test
matched its own string literals and passed regardless of load order.
Bound both ordering tests to their function body so a stale needle fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 36f3268 Oct 22, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/release-perf/stats-report branch October 22, 2026 22:26
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