tower_acc/algorithm.rs
1use std::time::Duration;
2
3/// An algorithm that dynamically adjusts the maximum number of allowed concurrent requests based on the observed traffic.
4pub trait Algorithm {
5 /// Returns the maximum number of concurrent requests the algorithm currently allows.
6 ///
7 /// # Panics
8 ///
9 /// Implementations **must not** panic. This method is called while holding
10 /// a shared mutex; a panic would poison it and abort on the next request.
11 fn max_concurrency(&self) -> usize;
12
13 /// Observes the outcome of a request and updates the algorithm's state accordingly.
14 ///
15 /// # Panics
16 ///
17 /// Implementations **must not** panic. This method is called while holding
18 /// a shared mutex; a panic would poison it and abort on the next request.
19 fn update(&mut self, rtt: Duration, num_inflight: usize, is_error: bool, is_canceled: bool);
20}