#bongonet #async #non-blocking

bongonet-timeout

Highly efficient async timer and timeout system for Tokio runtimes

1 unstable release

0.4.0 Nov 25, 2024

#1384 in Asynchronous

Download history 146/week @ 2024-11-25 1/week @ 2024-12-02 7/week @ 2024-12-09

154 downloads per month
Used in bongonet-pool

Apache-2.0

23KB
398 lines

A drop-in replacement of tokio::time::timeout which is much more efficient.

Similar to tokio::time::timeout but more efficient on busy concurrent IOs where timeouts are created and canceled very frequently.

This crate provides the following optimizations

  • The timeouts lazily initializes their timer when the Future is pending for the first time.
  • There is no global lock for creating and cancelling timeouts.
  • Timeout timers are rounded to the next 10ms tick and timers are shared across all timeouts with the same deadline.

Benchmark:

438.302µs total, 4ns avg per iteration

v.s. Tokio timeout():

10.716192ms total, 107ns avg per iteration

Dependencies

~2.6–8.5MB
~75K SLoC