-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Provide boottime timers #3185
Comments
I'm not too familiar with the timing facilities. Which OS waiting functionality should we use to hook into these timers? |
I believe among platforms only Posix/Linux allows to configure which clock to use |
I've checked the epoll_wait implementation and I haven't seen any reason for this restriction except that nobody has implemented support for other clocks yet. The commit that added boottime support to timerfds was trivial and epoll_wait seems to be using the same infrastructure for timers: torvalds/linux@4a2378a943f09 The only way to use boottime timers with all currently supported linux versions seems to be via timerfds. This integrates nicely with the existing tokio infrastructure via AsyncFd. I haven't looked at other operating systems. |
Since tokio is cross-platform, it would need consistent behavior across all platforms. |
On OpenBSD and macOS, the monotonic clocks are boottime clocks FreeBSD does not seem to have a boottime clock. Windows does not have any direct support for boottime sleep. However, you can use RegisterSuspendResumeNotification to get notified upon suspend/resume so that you can adjust the existing timers accordingly. |
The current behavior is not consistent because
|
This has come up again with In our use case, a networking daemon with long-lived connections (~3 minutes) is losing connections without realizing it on Android because the device has been suspended. This results in the service being unresponsive for up to three minutes after unlock if the suspend came at a perfectly bad time, and having hit more than a minute in the field when unlucky. We've tried to work around it, but without Even if While I am of the opinion that tl;dr: In order for |
What restrictions did you run into? Would it not be possible to create a future that expires after |
Regarding changing If you just want a separate set of timers that work with CLOCK_BOOTTIME, then that would be pretty easy since you can use a timerfd via Tokio's |
Just an update: It seems like std is going to switch to using CLOCK_BOOTTIME in rust-lang/rust#88714. We will need to implement support for that in Tokio by changing the timer driver to use a timerfd for timeouts. I think a reasonable plan is to implement that PR once the change is available in nightly so we can test it. We can hold off on merging it until it arrives in stable. |
rust-lang/rust#88714 got closed. There is an upstream bug report for Rust at rust-lang/rust#71860
Go tried to switch from I suggest to copy Go decision and provide new type of timers instead of considering trying to change existing ones. |
io_uring provides |
Boot-time: "This library reimplements std::time::Instant to use suspend-aware monotonic time if target system supports it. Otherwise it uses monotonic time or reexports std::time::Instant." Will be obsoleted when tokio-rs/tokio#3185 is resolved. Fixes redlib-org#22
Is your feature request related to a problem? Please describe.
On linux, tokio currently delegates to std::sync::Condvar::wait_timeout and epoll_wait. These functions use CLOCK_MONOTONIC. Therefore, time spent in system sleep does not count towards tokio timers.
Sometimes you want to schedule an operation periodically. For example, poll an external resource once an hour. CLOCK_MONOTONIC is not suitable for this usecase. After the system wakes up from sleep, you most likely want to poll the external resource immediately if a wall clock hour has elapsed.
Describe the solution you'd like
Provide some way to create CLOCK_BOOTTIME timers.
Describe alternatives you've considered
This can be implemented as an external library. But tokio already contains the infrastructure to work with timers.
Additional context
I assume timeouts are also affected by sleep not counting towards them.
On Windows, std::sync::Condvar::wait_timeout behaves the same way. However, due to rust-lang/rust#79462, any spurious wakeup will cause the timer to expire.
The text was updated successfully, but these errors were encountered: