Repository navigation
feat(timer-wheel): an approximate per-thread timer wheel - #1990
Closed
daniel-noland wants to merge 1 commit into
Closed
daniel-noland wants to merge 1 commit into
daniel-noland wants to merge 1 commit into
Conversation
Per-flow tokio timer tasks collapse the gateway at a million flows: every refreshed flow re-arms a task on the shared management runtime, which convoys on its locks until BGP drops. A single-level wheel owned by the worker thread avoids the runtime entirely. Timers do not store their deadline; the payload is asked when its bucket comes due and is moved if the deadline went later, so a refresh costs the refresher only its own store. Entries live in a slab with an intrusive list per bucket: insert and cancel are O(1). Each sweep does a bounded amount of work and hands fired and cancelled payloads back as a batch. Other threads cancel through a TimerRef and schedule through a Remote; both queue for the owner's next sweep. A timer fires no earlier than its deadline and, unless the wheel is behind, within a tick of it. A model-based property test checks this against a map of deadlines, with cancellation, refresh, wrap-around and budgets; a concurrency test runs under loom and shuttle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
Closed in favor of #2004. |
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.
First of a stack that takes flow and NAT-mapping expiry off tokio, with no async on the workers. This PR adds only the generic crate. The next two PRs put flows and mapping reapers on it.
Why
On env-5's bare-metal gateway, per-flow tokio timers are a failure mode, not a slowdown:
A synchronous per-worker wheel removes all three. Details are in the env-5 notes (
SUMMARY.md, E1-E3) and can be shared.Design (
timer-wheel/)WheelConfig::standard()is 10 ms × 8192 slots. Longer deadlines wrap and are revisited.TimerIdcarries a generation, so a stale cancel is a no-op.sweep(now, budget, &mut out)looks at mostbudgetdue entries and hands backFired::{Due, Cancelled}in a batch. An avalanche of expiries cannot stall a worker's rx polling.TimerRef::cancelandRemote::schedulego through mutex-guarded queues from theconcurrencyfacade, so they also run under shuttle and loom. Cross-thread traffic is rare: invalidations, and config apply.concurrency::test.The stack
Further up, flow-state layout PRs make use of it. A docs PR is still to come.
🤖 Generated with Claude Code