| Crates.io | request-rate-limiter |
| lib.rs | request-rate-limiter |
| version | 0.2.3 |
| created_at | 2025-10-17 15:30:10.439848+00 |
| updated_at | 2025-11-01 14:05:56.285032+00 |
| description | Request rate limiting with adaptive algorithms for controlling request throughput |
| homepage | https://github.com/shajapas/request-rate-limiter |
| repository | https://github.com/shajapas/request-rate-limiter |
| max_upload_size | |
| id | 1887801 |
| size | 45,539 |
Dynamic request rate limiting with adaptive algorithms for controlling request throughput.
A Rust library for request rate limiting using adaptive algorithms. The library provides rate limiting that automatically adjusts request rates based on success/failure patterns, helping prevent overload while maximizing throughput.
P.S. The idea was taken from congestion-limiter crate
Loss-based rate limiting that increases the rate linearly on success and decreases it multiplicatively on overload.
Simple, constant rate limiting that maintains a fixed requests-per-second limit.
Add this to your Cargo.toml:
[dependencies]
request-rate-limiter = "0.1.0"
use std::sync::Arc;
use request_rate_limiter::{
algorithms::Aimd,
limiter::{DefaultRateLimiter, RateLimiter, RequestOutcome}
};
#[tokio::main]
async fn main() {
// Create a rate limiter with AIMD algorithm
let limiter = Arc::new(DefaultRateLimiter::new(
Aimd::new_with_initial_rate(10)
.decrease_factor(0.9)
.increase_by(1)
));
// Acquire permission to make a request
let token = limiter.acquire().await;
// Simulate doing work
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
// Release the token with outcome
limiter.release(token, Some(RequestOutcome::Success)).await;
println!("Request completed successfully!");
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.