Skip to main content

tower_acc/
lib.rs

1//! Adaptive concurrency control for [Tower] services.
2//!
3//! This crate provides a [`ConcurrencyLimit`] middleware that dynamically
4//! adjusts the number of in-flight requests based on observed latency, rather
5//! than requiring a fixed limit chosen at deploy time. It is inspired by
6//! Netflix's [concurrency-limits] library and the TCP Vegas congestion control
7//! algorithm.
8//!
9//! # Quick start
10//!
11//! ```rust,no_run
12//! use tower::ServiceBuilder;
13//! use tower_acc::{ConcurrencyLimitLayer, Vegas};
14//! # fn wrap<S>(my_service: S) -> impl tower_service::Service<()>
15//! # where S: tower_service::Service<(), Error = std::convert::Infallible> {
16//!
17//! let service = ServiceBuilder::new()
18//!     .layer(ConcurrencyLimitLayer::new(Vegas::default()))
19//!     .service(my_service);
20//! # service
21//! # }
22//! ```
23//!
24//! # Algorithms
25//!
26//! Three built-in algorithms are provided:
27//!
28//! - [`Aimd`] — loss-based (TCP Reno–style). Reacts to errors and timeouts.
29//! - [`Gradient2`] — gradient-based (Netflix-style). Compares long-term vs
30//!   short-term RTT with a configurable tolerance.
31//! - [`Vegas`] — queue-depth estimation (TCP Vegas–style). Tracks minimum RTT
32//!   as a no-load baseline.
33//!
34//! To implement a custom strategy, see the [`Algorithm`] trait.
35//!
36//! [Tower]: https://github.com/tower-rs/tower
37//! [concurrency-limits]: https://github.com/Netflix/concurrency-limits
38
39mod aimd;
40mod algorithm;
41mod classifier;
42mod controller;
43mod future;
44mod gradient2;
45#[cfg(feature = "layer")]
46mod layer;
47mod service;
48mod vegas;
49
50pub use self::aimd::Aimd;
51pub use self::algorithm::Algorithm;
52pub use self::classifier::{Classifier, DefaultClassifier};
53pub use self::gradient2::Gradient2;
54#[cfg(feature = "layer")]
55pub use self::layer::ConcurrencyLimitLayer;
56pub use self::service::ConcurrencyLimit;
57pub use self::vegas::Vegas;