throttle-machines

Crates.iothrottle-machines
lib.rsthrottle-machines
version0.1.0
created_at2025-12-27 22:26:13.043734+00
updated_at2025-12-27 22:26:13.043734+00
descriptionRate limiting algorithms: GCRA, token bucket, fixed window
homepage
repositoryhttps://github.com/seuros/throttle_machines
max_upload_size
id2007938
size16,810
Abdelkader Boudih (seuros)

documentation

README

throttle-machines

High-performance rate limiting algorithms for Rust.

Algorithms

  • GCRA (Generic Cell Rate Algorithm) - Smooth, precise per-request timing
  • Token Bucket - Allows burst capacity with steady refill rate
  • Fixed Window - Simple counter with TTL in current window

Usage

use throttle_machines::gcra;

let result = gcra::check(
    0.0,    // current TAT (Theoretical Arrival Time)
    1.0,    // current time
    0.1,    // emission_interval (period / limit)
    0.0,    // delay_tolerance (for burst allowance)
);

if result.allowed {
    println!("Request allowed, new TAT: {}", result.new_tat);
} else {
    println!("Rate limited, retry after: {}s", result.retry_after);
}

no_std Support

This crate is no_std compatible when the std feature is disabled:

[dependencies]
throttle-machines = { version = "0.1", default-features = false }

License

MIT

Commit count: 0

cargo fmt