Skip to main content

Module lease_timer_wheel

Module lease_timer_wheel 

Source
Expand description

Edge-triggered timer wheel for lease expiry / refresh scheduling.

Replaces the thread::sleep(ttl/3) polling loop in lease_loop with a bucket-granular timer wheel: the worker thread sleeps until the next bucket is due, fires all leases in that bucket, then sleeps again.

§Design (top-half / bottom-half)

  • Top-half (schedule / cancel): callable from any thread, O(log n).
  • Bottom-half (run_until_shutdown): dedicated worker thread; wakes only when a bucket fires. Zero CPU for idle leases.

Bucket granularity is configurable (default 100 ms). All expirations within the same granularity window coalesce into one wake-up.

§Scalability

With N idle leases all expiring far in the future, the worker sleeps exactly until the earliest bucket — not once per lease. CPU overhead is O(0) while idle and O(k) where k is the number of leases firing in the current bucket.

Structs§

LeaseTimerWheel
Timer wheel that schedules leases to fire at specific wall-clock times.

Type Aliases§

LeaseId