feat(mpmc): add capacity reservation to bounded senders - #334
BewareMyPower merged 3 commits into
Conversation
BewareMyPower
left a comment
There was a problem hiding this comment.
From your benchmark, this PR introduces performance regressions in many cases, could you explain the reason?
Larger BenchmarksI reran the bounded MPMC benchmarks with larger samples, alternating
I have updated that earlier claim from the PR description. Conclusion
|
so is it necessary? or could you figure out a better approach? |
To follow the contract described in #334, I think it's necessary now, and the alignment with Do you think performance is in this PR's scope? Then I'll try to do it further. |
|
I think it's okay, we can improve the performance later if possible. |
Summary
Closes #297.
BoundedSender::reserve,try_reserve, and a borrowedmpmc::Permitso callers can wait for capacity before constructing a message, as requested in #297.upstream/main:c42f549(contract tests) and28a0b14(implementation).Design Notes
Queued messages, held permits, and grants to waiting senders share the configured capacity. Sends and reservations receive grants in wait-queue order. Cancelling a granted operation or dropping an unused permit passes its slot to the next waiter. A permit reserves capacity, not message order, and
Permit::sendreturns the value if receivers have disconnected.Benchmarks
Lower is better. Results compare
upstream/main(0f46831) with this branch (28a0b14). Each value is the median of 10 Divan run medians on an Apple M3 Pro with Rust 1.98.0. Microbenchmarks use capacity 1; batch benchmarks use capacity 64 and transfer 16,384 messages per iteration.upstream/maintry_send→try_recvsend→recvsendtry_reserve→Permit::send→try_recvreserve→Permit::send→recvtry_reserve→ drop permitreserve→ drop permittry_reserveon a full queuereserve, then sendExisting single-thread round trips are 5.7%–13.5% slower. Batch results vary by topology and include both improvements and regressions; the largest measured regression is 15.2% for Tokio with 4 workers and 8 producers→1 consumer. Reservation-specific cases were measured in a temporary benchmark copy and are not part of this PR.
Validation
cargo x testpassed, including the bounded MPMC reservation tests and doctests.