-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recv_many for mpsc channels #6010
Commits on Oct 9, 2023
-
Method recv_many returns a Vec<T> for mpsc channels
Circumstances may exist where multiple messages are queued for the receiver by the time the receiving task runs -- and the receiving task itself may benefit from batch as opposed to item-by-item processing, e.g., update a row based on a primary key but only the most recent update is needed; recv_many enables the receiver to process messages last-first and skip earlier updates for rows already updated. The change involved introducing a peek function to sync/mpsc/list.rs; it is based on fn pop. fn recv_many returns Poll<Vec<T>> contrasting recv's Poll<Option<T>>. The new function returns Ready(vec![]) where recv returned Ready(None). The mpsc.rs trait Semaphore was extended with two functions, num_acquired() and add_permits(n) -- which are used to size the vector and update the underlying semaphores in a single call. Simple tests were added to tests/sync_mpsc.rs.
Configuration menu - View commit details
-
Copy full SHA for f13ea3e - Browse repository at this point
Copy the full SHA f13ea3eView commit details -
Update recv_many to populate a passed-in buffer.
The implementation uses a passed-in buffer to return results. The buffer is always cleared, and its capacity may be increased to match the number of queued messages. This avoids excessive memory allocation. This commit also adds new benchmarks in benches/sync_mpsc_recv_many.rs It borrows substantially from benches/sync_mpsc.rs The benchmarks are framed around the idea that only the last value is needed, e.g., what might be typical in a dashboard. The following benchmarks compare extracting the last value from 5_000 recv's vs. a variable number of recv_many: contention_bounded_updater_recv vs. contention_bounded_updater_recv_many contention_bounded_full_updater_recv vs. contention_bounded_full_updater_recv_many contention_unbounded_updater_recv vs. contention_unbounded_updater_recv_many uncontented_bounded_updater_recv vs. uncontented_bounded_updater_recv_many uncontented_unbounded_updater_recv vs. uncontented_unbounded_updater_recv_many Initial tests suggests a ~30% performance improvement for the uncontented tests. The benchmarks contention_bounded_updater_publish_recv and contention_bounded_updater_publish_recv_many are different; first the number of messages recevied are only 1_000. In these test, we contemplate an actor who needs to receive a message and forward it over an API that takes 1ns to complete. An actor accepting a single message-at-a-time will hit the 1ns lag repeatedly; the actor that can pick only the last message out of the buffer from recv_many has much less work.
Configuration menu - View commit details
-
Copy full SHA for 0133425 - Browse repository at this point
Copy the full SHA 0133425View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7d0d8db - Browse repository at this point
Copy the full SHA 7d0d8dbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 487f887 - Browse repository at this point
Copy the full SHA 487f887View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7086b34 - Browse repository at this point
Copy the full SHA 7086b34View commit details -
Update from bencher and merge benchmarks into sync_mpsc.rs
Previous benchmarks in sync_mpsc_recv_many.rs included a contrived example that is removed.
Configuration menu - View commit details
-
Copy full SHA for 9a170b0 - Browse repository at this point
Copy the full SHA 9a170b0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 01b2270 - Browse repository at this point
Copy the full SHA 01b2270View commit details -
Simplified recv_many implementation
Removed methods num_acquired and peek; allow caller to control the number of retrieved elements by setting the capacity of the result buffer. In the event the result buffer has no capacity, the capacity is set to BLOCK_CAP. Added examples to the documentation.
Configuration menu - View commit details
-
Copy full SHA for 8c8b06f - Browse repository at this point
Copy the full SHA 8c8b06fView commit details -
Fix test send_recv_unbounded for arbitrarty BLOCK_CAP values
Also, update test async_send_recv_many_with_buffer to test that buffer capacity is not increased by recv_many.
Configuration menu - View commit details
-
Copy full SHA for dc81be3 - Browse repository at this point
Copy the full SHA dc81be3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8f5b00c - Browse repository at this point
Copy the full SHA 8f5b00cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3c1dc33 - Browse repository at this point
Copy the full SHA 3c1dc33View commit details -
Configuration menu - View commit details
-
Copy full SHA for 757bc33 - Browse repository at this point
Copy the full SHA 757bc33View commit details -
Change to recv_many to no longer clear the output buffer
This commit changes the behavior of recv_many to no longer clear the supplied buffer on each call. Now, recv_many will append new messages to the end of the supplied buffer until it reaches capacity. The return value is the number of new messages added to the buffer. This may be useful for a caller who expects a fixed number of messages and wishes to avoid copying. At the time of the call, recv_many now asserts that the capacity of the buffer exceeds its length (fail-fast). The caller must appropriately clear/resize the buffer between calls if it is to be reused. The method recv_many no longer changes the capacity of the supplied buffer. Unit and doc and doc tests were updated to test and document the new behavior.
Configuration menu - View commit details
-
Copy full SHA for 0948857 - Browse repository at this point
Copy the full SHA 0948857View commit details -
Filled buffer handling now fail-safe, not fail-fast
Implements approach of Darksonn, where the buffer is extended when the capacity is equal to the length at the time of the call to recv_many.
Configuration menu - View commit details
-
Copy full SHA for 1dc2dbf - Browse repository at this point
Copy the full SHA 1dc2dbfView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6bf430c - Browse repository at this point
Copy the full SHA 6bf430cView commit details -
Configuration menu - View commit details
-
Copy full SHA for cdc3665 - Browse repository at this point
Copy the full SHA cdc3665View commit details -
Update tokio/src/sync/mpsc/unbounded.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 4c1321f - Browse repository at this point
Copy the full SHA 4c1321fView commit details -
Update tokio/src/sync/mpsc/unbounded.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 27ae226 - Browse repository at this point
Copy the full SHA 27ae226View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9a1d9bc - Browse repository at this point
Copy the full SHA 9a1d9bcView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7fca954 - Browse repository at this point
Copy the full SHA 7fca954View commit details -
Improved documentation for
recv_many
and added testThe documentation is changed to better highlight the limited circumstance in which `recv_many` may return 0, '..will never return 0 unless...'. Two new tests are somewhat analogous to the doctests were added: - send_recv_many_bounded_capacity() - send_recv_many_unbounded_capacity() These ensure that for buffers that have not reached their capacity a call to `recv_many` only fills up to the capacity leaving other messages still queued. A subsequent call on a filled buffer would reserve additional elements. The test also looks at pending messages holding the channel open -- compared to the doctest example which showcases non-dropped senders.
Configuration menu - View commit details
-
Copy full SHA for fe44b32 - Browse repository at this point
Copy the full SHA fe44b32View commit details -
Update tokio/src/sync/mpsc/bounded.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for aac0eda - Browse repository at this point
Copy the full SHA aac0edaView commit details -
Update tokio/src/sync/mpsc/bounded.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 088537c - Browse repository at this point
Copy the full SHA 088537cView commit details -
Configuration menu - View commit details
-
Copy full SHA for effb0e5 - Browse repository at this point
Copy the full SHA effb0e5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1fb08df - Browse repository at this point
Copy the full SHA 1fb08dfView commit details -
Configuration menu - View commit details
-
Copy full SHA for bd1ef3a - Browse repository at this point
Copy the full SHA bd1ef3aView commit details -
Updated
recv_many
to accept a new argumentlimit
Positive values of `limit` set the maximum number of elements that can be added to `buffer` in a single call. A zero value of `limit` sets the maximum number of elements that can be added to a default value, currently `super::BLOCK_CAP`.
Configuration menu - View commit details
-
Copy full SHA for d31fd17 - Browse repository at this point
Copy the full SHA d31fd17View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3cd2e46 - Browse repository at this point
Copy the full SHA 3cd2e46View commit details -
Change behavior of recv_many(buf, 0) to return 0 immediately.
Returning 0 immediately when limit=0 is consistent with the current take(0) behavior. Tests were updated.
Configuration menu - View commit details
-
Copy full SHA for 326fa53 - Browse repository at this point
Copy the full SHA 326fa53View commit details -
Configuration menu - View commit details
-
Copy full SHA for e8950ce - Browse repository at this point
Copy the full SHA e8950ceView commit details
Commits on Oct 11, 2023
-
Update tokio/src/sync/mpsc/chan.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for ead4ca6 - Browse repository at this point
Copy the full SHA ead4ca6View commit details -
Update tokio/src/sync/mpsc/chan.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 2fcb715 - Browse repository at this point
Copy the full SHA 2fcb715View commit details -
check the coop budget in limit==0 case
Aaron Schweiger authored and Aaron Schweiger committedOct 11, 2023 Configuration menu - View commit details
-
Copy full SHA for ba46b7c - Browse repository at this point
Copy the full SHA ba46b7cView commit details -
Aaron Schweiger authored and Aaron Schweiger committed
Oct 11, 2023 Configuration menu - View commit details
-
Copy full SHA for b1d1cae - Browse repository at this point
Copy the full SHA b1d1caeView commit details -
Update tokio/src/sync/mpsc/bounded.rs
Co-authored-by: Alice Ryhl <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for f162ca7 - Browse repository at this point
Copy the full SHA f162ca7View commit details -
Reflow doc comments; adjust comment in chan.rs
Aaron Schweiger authored and Aaron Schweiger committedOct 11, 2023 Configuration menu - View commit details
-
Copy full SHA for 9f39dc7 - Browse repository at this point
Copy the full SHA 9f39dc7View commit details
Commits on Oct 13, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 27e39d9 - Browse repository at this point
Copy the full SHA 27e39d9View commit details