mod aimd;
mod fixed;
use async_trait::async_trait;
use std::time::Duration;
use crate::limiter::RequestOutcome;
pub use aimd::Aimd;
pub use fixed::Fixed;
#[async_trait]
pub trait RateLimitAlgorithm {
fn requests_per_second(&self) -> u64;
async fn update(&self, sample: RequestSample) -> u64;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequestSample {
pub response_time: Duration,
pub current_rps: u64,
pub outcome: RequestOutcome,
pub timestamp: std::time::Instant,
}
impl RequestSample {
pub fn new(response_time: Duration, current_rps: u64, outcome: RequestOutcome) -> Self {
Self {
response_time,
current_rps,
outcome,
timestamp: std::time::Instant::now(),
}
}
}