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

Timer refactoring #2905

Merged
merged 4 commits into from
Oct 6, 2020
Merged

Timer refactoring #2905

merged 4 commits into from
Oct 6, 2020

Conversation

greenwoodcm
Copy link
Contributor

Motivation

I've been talking to @carllerche over the last few weeks about simplifying the implementation of the timer and delay implementation within the existing interface. This is the first stab at that refactor.

Solution

Changes included in this PR:

  1. remove the wheel::Poll struct. it appears to be a pretty thin wrapper around u64 that provides limited functionality/value
  2. remove the delay_queue module completely. in chatting with @carllerche it sounds like we're planning on moving that to tokio-util anyways
  3. once delay_queue is removed, we don't need the generic behavior that allows the timer wheel to operate on both a slab and stack state directly - the only concrete store used is the stack directly. so now that it is removed we can make the timer wheel non-generic.
  4. remove the Registration struct, which appears to be a fairly thin wrapper around the Entry struct with limited functionality/value.

This is my first foray into the tokio ecosystem, so it's very likely that I'm missing the motivation around why things are the way they currently are - very open to suggestions and corrections. I also view this as the first in a few different efforts to rework the timer implementation. My next area of focus will be to reduce the amount of state that is shared across the Entry struct, which is the point of synchronization between the timer driver and the Delay itself. Reducing the surface area of Entry will probably make the delay implementation slimmer and easier to reason about. I'm open to suggestions on that future work as well.

@greenwoodcm greenwoodcm marked this pull request as ready for review October 3, 2020 05:37
@Darksonn Darksonn added A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-time Module: tokio/time labels Oct 3, 2020
@Darksonn
Copy link
Contributor

Darksonn commented Oct 3, 2020

Relevant: #2897

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍. A solid cleanup.

There will be merge conflicts w/ #2897, but hopefully, it shouldn't be too bad.

the timer wheel uses the `wheel::Poll` struct as input when
advancing the timer to the next time step.  the `Poll` struct
contains an instant representing the time step to advance to
and also contains an optional and mutable reference to an
`Expiration` struct.  from what I can tell, the latter field
is only used in the context of polling the wheel and does not
need to be exposed outside of that method.  without the
expiration field the `Poll` struct is nothing more than a
wrapper around the instant being polled.  this change removes
the `Poll` struct and updates integration points accordingly.
@greenwoodcm
Copy link
Contributor Author

Rebased onto #2897 , no functional changes

@carllerche carllerche merged commit fcdf934 into tokio-rs:master Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-time Module: tokio/time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants