perf(message_bus): batch small replica frames per socket read - #4224
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4224 +/- ##
=============================================
- Coverage 87.53% 73.95% -13.58%
Complexity 1575 1575
=============================================
Files 1283 1282 -1
Lines 223461 204348 -19113
Branches 186824 167713 -19111
=============================================
- Hits 195605 151133 -44472
- Misses 23141 48550 +25409
+ Partials 4715 4665 -50
🚀 New features to boost your workflow:
|
hubcio
force-pushed
the
feat/msg-bus-bufreadwrite
branch
3 times, most recently
from
September 21, 2026 10:49
f980b26 to
1c41571
Compare
The link shard that owns a peer's replica socket burns a full core under sustained replicated writes. Nothing batches its reads: read_message issues one io_uring read for the 256-byte header and a second for the body. Bytes already sitting in the kernel receive queue wait for the next call. A read-ahead buffer sized by message_bus.replica_read_buffer_size lets one socket read serve a whole burst. It adds no latency, because the reader never waits for the buffer to fill. One fill delivers at most one buffer, so a body above that size crosses the buffer in buffer-sized pieces and pays one extra pass over the payload and one read per piece. A read that large goes straight into the frame's own buffer instead. Zero keeps the unbuffered path, so the A/B baseline is a config change and not a separate build. The plaintext writer already coalesces into one writev, so it is left alone. replica_socket_reads_total and replica_inbound_frames_total carry the evidence on the real workload: their ratio is the batching factor, and only link shards bump them. A read counts once it completes, so a link torn down mid-read cannot inflate the ratio.
The comments claimed a body crossing the read-ahead buffer pays at most one buffer of copying. That holds only for a body of two buffers or more. The bypass needs an empty buffer, and compio's read_exact shrinks the caller slice as the read proceeds (compio-io 0.10.1 src/read/ext.rs:168). The read that finishes a body of one to two buffers therefore arrives with less room than the buffer and refills instead of bypassing, so the payload crosses the buffer whole. Also record that 0, unlimited and none select the unbuffered path, and write "handed to the dispatcher" rather than "delivered" at shutdown: the reader drops frames when the dispatch queue closed first.
hubcio
force-pushed
the
feat/msg-bus-bufreadwrite
branch
from
September 21, 2026 12:33
1c41571 to
83539f5
Compare
mmodzelewski
approved these changes
Sep 21, 2026
spetz
approved these changes
Sep 21, 2026
numinnex
approved these changes
Sep 21, 2026
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.
The link shard that owns a peer's replica socket burns a full
core under sustained replicated writes. Nothing batches its reads:
read_message issues one io_uring read for the 256-byte header and
a second for the body. Bytes already sitting in the kernel receive
queue wait for the next call.
A read-ahead buffer sized by message_bus.replica_read_buffer_size
lets one socket read serve a whole burst. It adds no latency, because
the reader never waits for the buffer to fill. One fill delivers
at most one buffer, so a body above that size crosses the buffer in
buffer-sized pieces and pays one extra pass over the payload and one
read per piece. A read that large goes straight into the frame's own
buffer instead.
Zero keeps the unbuffered path, so the A/B baseline is a config change
and not a separate build. The plaintext writer already coalesces into
one writev, so it is left alone.
replica_socket_reads_total and replica_inbound_frames_total carry the
evidence on the real workload: their ratio is the batching factor,
and only link shards bump them. A read counts once it completes,
so a link torn down mid-read cannot inflate the ratio.