Skip to content
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

Rewrite the mpsc channels #984

Closed
wants to merge 1 commit into from
Closed

Commits on Apr 24, 2018

  1. Rewrite the mpsc channels

    Previously, the bounded mpsc channels wouldn't provide backpressure
    in many cases because they provided a guaranteed slot for every
    sender. This change refactors mpsc channels to never allow more than
    buffer + 1 messages in-flight at a time.
    
    Senders will attempt to increment the number of in-flight messages
    in poll-ready. If successful, the count is incremented and a message
    is sent. If the buffer was full, the sender adds itself to a queue
    to be awoken. When a message is received, the receiver attempts to
    awaken a Sender and grant it "sending rights". If no such channel
    was found, it decreases the number of in-flight messages currently
    present in the buffer.
    
    There's one odd choice in this change, which was to pick buffer + 1
    rather than buffer as the max number of elements. In practice, many
    of the tests and a handful of real-world code relied on the ability
    to have an initial element available for the first sender, and were
    attempting to send into channels with a buffer size of zero. These
    use-cases were all broken by this change without the change to use
    buffer + 1.
    
    Despite the buffer + 1 mitigation, this is still a breaking change
    since it modifies the maximum number of elements allowed into a
    channel. 0.2 has been out for a short enough time that it's probably
    possible to transition without breaking existing code, but this
    approach should be taken with caution. Luckily, 0.2 organized
    futures-channel into a separate crate, so it could be released as
    an 0.3 version of futures-channel, futures-sink, futures-util, and
    the futures facade while still maintaining futures-io and futures-core
    compatibility.
    cramertj committed Apr 24, 2018
    Configuration menu
    Copy the full SHA
    d732372 View commit details
    Browse the repository at this point in the history