tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
27.05k stars 2.49k forks source link

hierarchical timer wheels #4593

Closed journaux closed 2 years ago

journaux commented 2 years ago

Ive been using the delay queue quite often - https://github.com/tokio-rs/tokio/blob/cf38ba627abb0d44ae7e7dc0659ddd51866e9efa/tokio-util/src/time/delay_queue.rs

I was curious whether any of the wonderful authors of this library thought about hierarchical timer wheels as an alternative/better approach - https://blog.acolyer.org/2015/11/23/hashed-and-hierarchical-timing-wheels/

For small queue sizes, of course, cache locality will dictate perf. For large queue sizes, on the order of magnitude of Kafka/Linux kernel/Windows kernel, these schedulers all take the form of hierarchal timer wheels to reduce O(n) -> O(lgn)

I'm asking as we plan on eventually building a distributed hierarchal timer wheel partitioned & replicated w/ gossip protocols. A native, thoughtful approach would help greatly :)

Darksonn commented 2 years ago

Do we not already use a hashed hierarchical timing wheel?

journaux commented 2 years ago

good point

i was incorrectly classifying the wheel type

https://github.com/tokio-rs/tokio/tree/master/tokio-util/src/time/wheel

thank you!