Expand description
§AeroRate
aerorate is an ultra-fast, lock-free rate limiter implementing the Generic Cell Rate Algorithm (GCRA).
Designed for high-frequency trading gateways, reverse proxies, and high-throughput microservices.
§Key Architecture Highlights
- Sub-10 Nanosecond Evaluation: Evaluates requests via a lock-free atomic CAS loop on a single
AtomicU64timestamp. - Zero Memory Allocations: Hot path checks require zero heap allocations.
- Keyed Multi-Tenant Limiting: Sharded across power-of-two, cache-line padded partitions (
#[repr(align(64))]) to eliminate false sharing. - Borrowed Key Queries: Query with
&stronStringkeys without cloning. - Rich HTTP Telemetry: Yields
retry_after,remaining_burst, andreset_afterfor standard HTTP headers. - 100% Safe Rust:
#![forbid(unsafe_code)]strictly enforced.
§Quick Start
use aerorate::{RateLimiter, Quota};
use std::time::Duration;
// Allow 100 requests per second with burst allowance up to 20
let limiter = RateLimiter::new(Quota::per_second(100).allow_burst(20));
match limiter.check() {
outcome if outcome.is_allowed() => {
println!("Allowed! Remaining burst: {}", outcome.remaining_burst());
}
outcome => {
println!("Throttled! Retry after: {:?}", outcome.retry_after());
}
}§Multi-Tenant / Per-Key Rate Limiting
use aerorate::{KeyedRateLimiter, Quota};
// Rate limit per IP address or API key
let limiter: KeyedRateLimiter<String> = KeyedRateLimiter::per_second(10);
// Zero-allocation lookup using borrowed &str
let client_ip = "192.168.1.100";
if limiter.check(client_ip).is_allowed() {
println!("Request accepted for {}", client_ip);
}Re-exports§
pub use keyed::KeyedRateLimiter;pub use limiter::RateLimiter;pub use metrics::RateMetrics;pub use outcome::RateLimitResult;pub use quota::Quota;
Modules§
- keyed
- Keyed multi-tenant rate limiter with cache-line padded sharding.
- limiter
- Single-target lock-free rate limiter.
- metrics
- Telemetry metrics and snapshot tracking.
- outcome
- Rate limit evaluation outcomes and HTTP header helpers.
- quota
- Quota specifications and GCRA parameters.
- state
- Internal lock-free atomic GCRA state.
Type Aliases§
- String
Rate Limiter - Type alias for a keyed rate limiter where keys are
String.