1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! 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:
//! 1. **Additive Increase**: For each successful request window, increase the concurrency limit by 1
//! 2. **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
extern crate tracing;
extern crate serde_json; // For example payload
pub type Error = ;