congestion_limiter/limits/
mod.rs

1//! Algorithms for controlling concurrency limits.
2
3mod aimd;
4mod defaults;
5mod fixed;
6mod gradient;
7mod vegas;
8mod windowed;
9
10use async_trait::async_trait;
11use std::time::Duration;
12
13use crate::limiter::Outcome;
14
15pub use aimd::Aimd;
16pub use fixed::Fixed;
17pub use gradient::Gradient;
18pub use vegas::Vegas;
19pub use windowed::Windowed;
20
21/// An algorithm for controlling a concurrency limit.
22#[async_trait]
23pub trait LimitAlgorithm {
24    /// The current limit.
25    fn limit(&self) -> usize;
26
27    /// Update the concurrency limit in response to a new job completion.
28    async fn update(&self, sample: Sample) -> usize;
29}
30
31/// The result of a job (or jobs), including the [Outcome] (loss) and latency (delay).
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct Sample {
34    pub(crate) latency: Duration,
35    /// Jobs in flight when the sample was taken.
36    pub(crate) in_flight: usize,
37    pub(crate) outcome: Outcome,
38}