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
52
53
54
55
56
57
//! Adaptive concurrency control for [Tower] services.
//!
//! This crate provides a [`ConcurrencyLimit`] middleware that dynamically
//! adjusts the number of in-flight requests based on observed latency, rather
//! than requiring a fixed limit chosen at deploy time. It is inspired by
//! Netflix's [concurrency-limits] library and the TCP Vegas congestion control
//! algorithm.
//!
//! # Quick start
//!
//! ```rust,no_run
//! use tower::ServiceBuilder;
//! use tower_acc::{ConcurrencyLimitLayer, Vegas};
//! # fn wrap<S>(my_service: S) -> impl tower_service::Service<()>
//! # where S: tower_service::Service<(), Error = std::convert::Infallible> {
//!
//! let service = ServiceBuilder::new()
//! .layer(ConcurrencyLimitLayer::new(Vegas::default()))
//! .service(my_service);
//! # service
//! # }
//! ```
//!
//! # Algorithms
//!
//! Three built-in algorithms are provided:
//!
//! - [`Aimd`] — loss-based (TCP Reno–style). Reacts to errors and timeouts.
//! - [`Gradient2`] — gradient-based (Netflix-style). Compares long-term vs
//! short-term RTT with a configurable tolerance.
//! - [`Vegas`] — queue-depth estimation (TCP Vegas–style). Tracks minimum RTT
//! as a no-load baseline.
//!
//! To implement a custom strategy, see the [`Algorithm`] trait.
//!
//! [Tower]: https://github.com/tower-rs/tower
//! [concurrency-limits]: https://github.com/Netflix/concurrency-limits
pub use Aimd;
pub use Algorithm;
pub use ;
pub use Gradient2;
pub use ConcurrencyLimitLayer;
pub use ConcurrencyLimit;
pub use Vegas;