pub struct WheelBuilder { /* private fields */ }Expand description
Builder for configuring a timer wheel.
Defaults match the Linux kernel timer wheel (1ms tick, 64 slots/level, 8x multiplier, 7 levels → ~4.7 hour range).
§Examples
use std::time::{Duration, Instant};
use nexus_timer::{Wheel, WheelBuilder};
let now = Instant::now();
// All defaults
let wheel: Wheel<u64> = WheelBuilder::default().unbounded(4096).build(now).unwrap();
// Custom config
let wheel: Wheel<u64> = WheelBuilder::default()
.tick_duration(Duration::from_micros(100))
.slots_per_level(32)
.unbounded(4096)
.build(now)
.unwrap();Implementations§
Source§impl WheelBuilder
impl WheelBuilder
Sourcepub fn tick_duration(self, d: Duration) -> Self
pub fn tick_duration(self, d: Duration) -> Self
Sets the tick duration. Default: 1ms.
Sourcepub fn slots_per_level(self, n: usize) -> Self
pub fn slots_per_level(self, n: usize) -> Self
Sets the number of slots per level. Must be a power of 2, at most 64, and
greater than 2^clk_shift so a rebalance always moves an entry to a
strictly finer level (clk_shift and slots_per_level are validated
together at build). Default: 64.
Sourcepub fn clk_shift(self, s: u32) -> Self
pub fn clk_shift(self, s: u32) -> Self
Sets the bit shift between levels (multiplier = 2^clk_shift). Must satisfy
2^clk_shift < slots_per_level so a rebalance always moves an entry to a
strictly finer level (validated at build); with the default 64 slots that
allows clk_shift up to 5. Default: 3 (8x).
Sourcepub fn num_levels(self, n: usize) -> Self
pub fn num_levels(self, n: usize) -> Self
Sets the number of levels. Default: 7.
Sourcepub fn max_rebalances_per_poll(self, n: usize) -> Self
pub fn max_rebalances_per_poll(self, n: usize) -> Self
Sets the maximum number of entries rebalanced (moved to a finer
level) per poll_and_rebalance.
Default: usize::MAX (unbounded).
Rebalancing is maintenance: as time advances, a timer scheduled far in
the future is placed in a coarse level, and when its slot comes due it is
moved down to a finer level so it is not re-scanned on every future poll.
Unbounded (the default), one poll rebalances a whole slot at once — least
total work, but a rare poll can spike. A cap spreads that work across
several polls: each poll rebalances at most n entries and leaves the
rest in place, trading the rare spike for slightly more total work (the
leftover entries are walked again on a later poll).
This bounds only rebalancing, never firing. Every due timer is still collected at its exact deadline regardless of the cap, because a not-yet-due entry left un-rebalanced simply fires from whatever level it is sitting in when its time comes. The cap can therefore never make a timer fire late or be missed; it is purely a latency-smoothing knob for the poll hot path.
Recommended to tune for latency-sensitive loops: pick n large
enough to keep up with the steady rebalance rate (roughly
population * num_levels / average_timeout_in_ticks) so entries do not
backlog, yet small enough that no single poll stalls.
Sourcepub fn unbounded(self, chunk_capacity: usize) -> UnboundedWheelBuilder
pub fn unbounded(self, chunk_capacity: usize) -> UnboundedWheelBuilder
Transitions to an unbounded wheel builder.
chunk_capacity is the slab chunk size (entries per chunk). The slab
grows by adding new chunks as needed.
Sourcepub fn bounded(self, capacity: usize) -> BoundedWheelBuilder
pub fn bounded(self, capacity: usize) -> BoundedWheelBuilder
Transitions to a bounded wheel builder.
capacity is the maximum number of concurrent timers.