subms-rate-limiter 0.10.0

submillisecond.com cookbook recipe - concurrency: subms-rate-limiter. Lock-free GCRA-style rate limiter with a single-atomic CAS-loop.
Documentation

Rate limiter - Rust

Lock-free GCRA rate limiter using a single-atomic CAS-loop. One tryAcquire is one load and one CAS, even at 8-way contention.

Part of the submillisecond.com cookbook. Zero external dependencies; std only.

Install

[dependencies]
subms-rate-limiter = "0.4"

Quickstart

cargo test --release
cargo run --example demo

Public API

  • pub struct RateLimiter
  • pub fn new(rate_per_sec: f64, burst_capacity: u64) -> Self
  • pub fn try_acquire(&self) -> bool
  • pub fn rate_per_sec(&self) -> f64
  • pub fn burst_capacity(&self) -> u64

Files

  • src/lib.rs - implementation.
  • tests/ - integration tests; correctness, edge cases, property/stress.
  • examples/demo.rs - stdout walkthrough.
  • examples/perf_main.rs - bench entry (behind the harness feature).

License

Dual-licensed under MIT OR Apache-2.0.