Skip to main content

WheelBuilder

Struct WheelBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new builder with default configuration.

Source

pub fn tick_duration(self, d: Duration) -> Self

Sets the tick duration. Default: 1ms.

Source

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.

Source

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).

Source

pub fn num_levels(self, n: usize) -> Self

Sets the number of levels. Default: 7.

Source

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.

Source

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.

Source

pub fn bounded(self, capacity: usize) -> BoundedWheelBuilder

Transitions to a bounded wheel builder.

capacity is the maximum number of concurrent timers.

Trait Implementations§

Source§

impl Clone for WheelBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for WheelBuilder

Source§

impl Debug for WheelBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WheelBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.