Repository navigation
Timers - #7
Merged
Merged
Timers#7
Conversation
Protocol-agnostic hierarchical timer wheel to replace O(n) TCP timer scanning. Designed for 10k+ connections with extensibility for DNS and QUIC timer consumers.
Introduces TimerWheel with three-tier hierarchical layout (1ms/256ms/65.5s resolution), TimerId/TimerHandle types, and the arm()/is_armed() operations backed by a Slab and per-slot doubly-linked lists.
Implements cancel() on TimerWheel with full doubly-linked list unlinking (head, middle, tail cases) and silent no-op on already-cancelled handles. Five TDD tests cover all unlink positions and the idempotent cancel case.
Implements advance(now_ms) which drains inner wheel slots tick by tick, cascades middle-tier entries to the inner wheel on inner-wrap, and cascades outer-tier entries to the middle wheel on middle-wrap. cascade() collects all entries before re-arming to avoid slab aliasing.
Adds four cascade tests: middle-to-inner placement after inner-wrap, correct firing tick after cascade, outer-to-middle cascade at the 65536 boundary, and simultaneous firing of multiple cascaded entries.
Adds entry_count() -> usize (delegates to slab len). Adds seven edge case tests: re-arm after cancel, arm at current tick, arm in past (slot wrap), entry_count tracking, advance noop when time unchanged, burst catch-up across multiple slots, and no-fire when no timers due.
Introduces timer_kinds.rs with the TcpTimerKind enum (6 variants, repr(u8)), free functions for packing/unpacking TimerId with a connection key and timer kind, and TcpTimerHandles for per-connection handle storage. Adds TimerHandle::from_raw(crate-visible) constructor to support tests.
Add individual fire_delayed_ack, fire_retransmit, fire_keep_alive, fire_persist, fire_linger, fire_time_wait, and handle_timer methods alongside existing poll_timers()/evict_stale(). These methods operate on a single connection by slab key, enabling O(1) timer-wheel dispatch instead of O(n) scanning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.