ChronoMachines (Rust Core)
Pure Rust exponential backoff and retry library with full jitter support.
Features
- Multiple Backoff Strategies: Exponential, Constant, and Fibonacci
- Full Jitter: Prevents thundering herd problem by randomizing delays
no_stdCompatible: Works in embedded environments (with optionalalloc)- Zero Allocation: Core delay calculations use stack-only data structures
- Retry Builder: Fluent
.retry()API returning richRetryOutcome - Instrumentation Hooks: Separate
notify,on_success, andon_failurecallbacks - Named Policies: Optional registry (std/alloc) with global helpers
- ESP32 Ready: Tested on embedded systems
- Fast: Minimal overhead for retry operations
Usage
Add to your Cargo.toml:
[]
= "0.2"
Basic Example
use Policy;
let policy = Policy ;
// Calculate delay for first retry using full jitter (1.0)
let delay_ms = policy.calculate_delay;
println!;
With Custom RNG (no_std)
use Policy;
use SmallRng;
use SeedableRng;
let policy = default;
let mut rng = seed_from_u64;
// Calculate delay with 50% jitter (0.5)
let delay = policy.calculate_delay_with_rng;
Fluent Retry Builder
use ;
let mut attempts = 0;
let operation = ;
#
let outcome = operation
.retry
.notify
.on_success
.on_failure
.call
.expect;
println!;
println!;
Named Policies & DSL (requires std)
use ;
register_global_policy;
let outcome = retry_with_policy
.expect;
assert_eq!;
Algorithm
ChronoMachines implements full jitter exponential backoff:
delay = random(0, min(base * multiplier^(attempt-1), max)) // with jitter_factor = 1.0
This approach:
- Calculates exponential backoff:
base * multiplier^(attempt-1) - Caps at
max_delay_ms - Applies configurable jitter: blends between deterministic and random delay based on
jitter_factor
Why Full Jitter?
Full jitter prevents the "thundering herd" problem where multiple clients retry simultaneously, overwhelming a recovering service. By randomizing the delay, retries are naturally distributed over time.
Features
std (default)
Enables standard library support and StdRng for calculate_delay() method.
no_std
Disable default features for no_std environments:
[]
= { = "0.2", = false }
You'll need to provide your own RNG and use calculate_delay_with_rng().
alloc
Enable the lightweight, vector-backed PolicyRegistry without the standard
library:
[]
= { = "0.2", = false, = ["alloc"] }
Backoff Strategies
Exponential Backoff
Delays grow exponentially: base * multiplier^(attempt-1)
use ;
operation.retry.call
Constant Backoff
Fixed delay with optional jitter
use ;
operation.retry.call
Fibonacci Backoff
Delays grow by Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13...
use ;
operation.retry.call
License
MIT