drpcstream: byte-account the per-stream receive queue - #93
Open
suj-krishnan wants to merge 1 commit into
Open
Conversation
The receive queue (ringBuffer) bounded the producer by message-slot count: a fixed 256-slot ring blocking on count == len(buf). Slot-based bounding makes the flow-control memory bound a fiction -- a slow consumer can buffer 256 arbitrarily large messages -- so the "receiver holds <= StreamWindow + MaxMessageSize" guarantee does not hold. Grants are already byte-accurate (recvw.consumed(len)); the queue that holds those bytes was not. Bound and account the queue in bytes when flow control is enabled. The budget is StreamWindow + MaxMessageSize -- the per-stream receive peak (a window of un-granted bytes plus one message overdrafting to finish) -- and, crucially, is denominated in payload bytes: the same unit the sender debits and grants return. Admission (admits) includes the incoming message's length with an empty-queue exception, so the queue never overshoots the budget by a message and an oversized message is still deliverable. The pooled copy is made only after admission, so a blocked Enqueue holds no buffer outside the accounted queue. Under a budget the ring grows past its initial capacity, so message count never blocks the producer; flow control off keeps the legacy slot bound unchanged. Keeping the budget in payload bytes (rather than charging a per-entry overhead) preserves flow-control liveness: a conforming sender within its wire credit cannot fill the queue and block the shared connection reader. Bounding the per-message memory overhead and zero-credit (empty) message floods is left to follow-ups -- ownership transfer to drop the copy, and, for empty messages, a per-message minimum charged symmetrically in send credit, grants, and the queue. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
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.
Stacked on #92 (base:
sujatha/flow-control-overdraft).Problem
The receive queue (
ringBuffer) bounded the producer by message-slot count — a fixed 256-slot ring blocking oncount == len(buf). Slot-based bounding makes the flow-control memory bound a fiction: a slow consumer can buffer 256 arbitrarily large messages, so the "receiver holds ≤StreamWindow + MaxMessageSize" guarantee doesn't hold. Grants are already byte-accurate (recvw.consumed(len)); the queue that holds those bytes was not.Change
Bound and account the queue in bytes when flow control is on:
StreamWindow + MaxMessageSize— the per-stream receive peak (a window of un-granted bytes plus one message overdrafting to finish).manageReader).admits) folds in the incoming message's length with an empty-queue exception, so the queue never overshoots by a message and an oversized message is still deliverable.Enqueueholds no buffer outside the accounted queue.Deferred
Enqueuecopy and the assembler's retained backing array) — closes the accounted-vs-retained gap; a follow-up.Testing
go test ./drpcstream/ ./drpcmanager/ ./drpcwire/ -race(and the full suite) pass; gofmt clean. New ring-buffer tests cover byte-budget blocking/unblocking, incoming-length admission, byte release on dispatch, oversized-on-emptyacceptance, and ring growth; a stream-level test asserts the budget is
StreamWindow + MaxMessageSize(and unset when flow control is off).Part of CRDB-65748.