Skip to content

perf(qmux): batch writer frames, flushing the transport once - #397

Open
pouriya wants to merge 1 commit into
moq-dev:mainfrom
pouriya:qmux-batch-writer-frames
Open

pouriya wants to merge 1 commit into
moq-dev:mainfrom
pouriya:qmux-batch-writer-frames

Conversation

@pouriya

@pouriya pouriya commented Sep 20, 2026

Copy link
Copy Markdown

The problem

Fanning out to ~2400 WebSocket viewers, 66% of the relay's sendto calls
carried 8–15 bytes, and 51% of outbound packets were under 64 bytes. Every
frame is flushed as it is written, so small writes never coalesce — each one
costs a syscall, a segment and an ACK.

The change

Writer gains feed and flush. The writer feeds the frames already queued —
up to 64 KiB or 256 frames, in the existing priority order — then flushes once.
Each qmux frame is still its own WebSocket message; only the flush is shared.

Both methods have defaults that keep today's behaviour, so an external
impl Writer compiles and behaves unchanged. No public signature changed.

Measured

FreeBSD 15.1, 8 vCPU. Same host, same publisher, same load, before and after:

Before After
sendto/s 150k 26k
Outbound packets/s 91k 28k
Packets carrying 1–63 bytes 51% 7%
Relay cores per Gbps ~5.1 ~2.5

Tests

New: queued_frames_are_fed_then_flushed_once queues a three-write media frame
and asserts it produces one flush instead of three, with payloads and stream
offsets unchanged. It fails against main.

The session writer flushed after every frame, so each small frame cost
one syscall and one TCP segment. It now feeds the frames already queued
and flushes once.
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fabe4a92-8017-4de4-be38-f2a0e86573cd

📥 Commits

Reviewing files that changed from the base of the PR and between 1661201 and f0c9607.

📒 Files selected for processing (3)
  • rs/qmux/src/sched.rs
  • rs/qmux/src/session.rs
  • rs/qmux/src/transport.rs

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

PriorityQueue now supports synchronous removal of the next queued frame. The Writer trait now separates queuing data from flushing. StreamWriter buffers framed payloads and flushes them explicitly. WsWriter queues binary messages and flushes the sink explicitly. Default implementations preserve behavior for other Writer implementations.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: batching writer frames and flushing the transport once.
Description check ✅ Passed The description is directly related to the changeset. It explains the batching behavior, compatibility defaults, performance results, and test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Create a new PR

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.98.0)

Clippy execution timed out


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.

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