Repository navigation
fix: improve command channel buffer sizing under high write load - #1199
Merged
Merged
Conversation
Replace linear +5000 buffer growth with doubling strategy to reduce reallocations under sustained load (O(log n) vs O(n) allocations). Key changes: - readable() now grows front buffer before giving up, fixing #1050 where the channel silently stopped reading when the buffer was full - Add Buffer::shrink() to reclaim memory after peak usage subsides - Auto-shrink buffers back to initial_size when drained - Log warnings at 80% buffer utilization (high watermark) - Improve error variants with capacity, message_len, and max context - Add 4 targeted tests for growth, cap, shrink, and readable behavior Closes #1050
…prove tests The back buffer growth loop in write_delimited_message was capping each iteration at `needed` via `min(..., needed)`, which defeated the doubling strategy — the buffer always grew to exactly the minimum required size, losing amortization for future writes. Remove the inner cap so the loop overshoots to the next power-of-two boundary (still bounded by max_buffer_size on exit). Also: - Replace the misleading `front_buffer_grows_on_readable` test (which only tested `grow_size()`, duplicating `buffer_grows_with_doubling_strategy`) with `back_buffer_grows_with_doubling_on_write` that exercises the actual write path and asserts doubling behavior. - Remove unnecessary `mut` on `writing_channel` in test. Signed-off-by: Florentin Dubois <[email protected]>
llenotre
approved these changes
Mar 12, 2026
jrcribb
pushed a commit
to jrcribb/sozu
that referenced
this pull request
Aug 10, 2026
…-sizing fix: improve command channel buffer sizing under high write load
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.
Summary
max_buffer_sizereadable()now grows front buffer before giving up instead of silently stoppingMessageTooLargeandBufferFullerror variants with diagnosticsBuffer::shrink()method ingrowable.rsReview fixes applied
write_delimited_messagewas a no-op —min(new_length, needed)inside the loop meant buffer grew to exact size every time, defeating amortization. Removed inner cap.Closes #1050
Test plan
cargo test --workspacepasses (4 new tests)cargo clippy --workspaceclean