Expand description
Adaptive concurrency rate limiter using AIMD (Additive Increase Multiplicative Decrease) algorithm
This crate provides middleware for reqwest-based HTTP clients that dynamically adjusts the maximum number of concurrent requests based on observed latency and error rates.
§Algorithm Overview
The AIMD algorithm:
- Additive Increase: For each successful request window, increase the concurrency limit by 1
- Multiplicative Decrease: When errors exceed threshold, decrease limit by factor (default: 0.9)
§Features
- Automatic concurrency tuning based on request latencies
- Configurable EWMA smoothing for latency measurements
- Error rate tracking for backoff decisions
- Reqwest middleware integration
§Performance
- Overhead: <1μs per request
- Suitable for high-throughput systems (tested up to 10k req/s)
§Safety & Concurrency
- Thread-safe: Uses atomic operations for all shared state
- No unsafe code
§Basic Usage
use rate_limiter_aimd::adaptive_concurrency::AdaptiveConcurrencySettings;
use rate_limiter_aimd::reqwest_integration::ReqwestService;
use reqwest::Client;
let settings = AdaptiveConcurrencySettings::default();
let client = ReqwestService::new(Client::new(), settings);
// Use client as you would normally with reqwest§Configuration
See adaptive_concurrency::AdaptiveConcurrencySettings for tuning parameters
§Metrics
Emits metrics via the InternalEvent trait
Modules§
- adaptive_
concurrency - Limit the max number of requests being concurrently processed.
Macros§
- assert_
downcast_ matches - register
- registered_
event - Macro to take care of some of the repetitive boilerplate in implementing a registered event. See the other events in this module for examples of how to use this.