feat(mpmc): add competing queues - #265
Open
mxsm wants to merge 2 commits into
Open
Conversation
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
asyncband::mpmcbounded and unbounded queues with cloneable senders and receivers.Closes #211
Design Notes
Queue storage, endpoint counts, capacity checks, and disconnection state are linearized under one private
Mutex<VecDeque<T>>. Separate internal semaphores track blocked receivers and capacity-waiting bounded senders, so an ordinary queue transition selects one waiter without coupling public endpoints to storage or waiter types.Dropping the final sender wakes all receivers, which first drain buffered values and then observe
Disconnected. Dropping the final receiver releases buffered values and wakes every blocked bounded sender so each pending send returns its own unsent value.The new
mpmcCargo feature is an independent compile, audit, and code-size boundary for the new public module. This keeps the implementation opt-in without placing MPMC APIs behind the existingmpscfeature; maintainers should confirm this boundary against the feature policy discussed in #216.Testing
cargo x check— passed the no-feature build, the standalonempmcandeventfeature builds, every other standalone feature build, and the all-feature build.cargo x test --no-capture— passed the full workspace suite, including 14 MPMC integration tests, upstream panic-recovery tests, and all documentation tests.cargo x lint— passed Clippy with warnings denied, rustfmt, Taplo, typos, license checks, and documentation generation.T: Send + !Syncendpoint traits, futureSendtraits, exact-once delivery, and bounded progress under 8P/8C contention.Performance
Command:
cargo bench -p benchmarks --bench ecosystem -- mpmcThe following values are median time per 16,384-value batch from the optimized Windows run after merging the current
main. Lower is better; the ratio compares Asyncband with the fastest result in the same row.Bounded, capacity 64
Unbounded
The largest observed median gap was 6.57x for unbounded 1P/8C, below the order-of-magnitude regression threshold in #211. The private mutex-backed queue is expected to serialize more heavily than async-channel in some producer or consumer skews; the benchmark matrix is retained so future changes can track and improve those paths.