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

update to Tokio 1.0 #489

Merged
merged 10 commits into from
Dec 23, 2020
Merged

update to Tokio 1.0 #489

merged 10 commits into from
Dec 23, 2020

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Dec 23, 2020

This branch updates Tower to depend on Tokio v1.0. In particular, the
following changes were necessary:

  • tokio::sync::Semaphore now has a close operation, so permit
    acquisition is fallible. Our uses of the semaphore are updated to
    handle this. Also, this allows removing the janky homemade
    implementation of closing semaphores by adding a big pile of
    permits!

  • tokio::sync's channels are no longer Streams. This necessitated a
    few changes:

    • Replacing a few explicit poll_next calls with poll_recv
    • Updating some tests that used mpsc::Receiver as a Stream to add
      a wrapper type that makes it a Stream
    • Updating CallAll's examples (I changed it to just use a
      futures::channel MPSC)
  • tokio::time::Sleep is no longer Unpin. Therefore, the rate-limit
    Service needs to Box::pin it. To avoid the overhead of
    allocating/deallocating Boxes every time the rate limit is
    exhausted, I moved the Sleep out of the State enum and onto the
    Service struct, and changed the code to reset it every time the
    service is rate-limited. This way, we only allocate the box once when
    the service is created.

There should be no actual changes in functionality.

@hawkw hawkw self-assigned this Dec 23, 2020
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
I also made a slight refactor here so that we use the same `Sleep`
future, and reset it, rather than constantly creating new ones whenever
the rate limit is exhausted. This avoids repeatedly allocating and
deallocating the Box that's now necessary to make the future Unpin.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw merged commit 45974d0 into master Dec 23, 2020
@hawkw hawkw deleted the eliza/tokio-1 branch December 23, 2020 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants