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//! # Pluggable algorithms
25//!
26//! The built-in [`Vegas`] algorithm works well for most workloads. To implement
27//! a custom strategy, see the [`Algorithm`] trait.
28//!
29//! [Tower]: https://github.com/tower-rs/tower
30//! [concurrency-limits]: https://github.com/Netflix/concurrency-limits
31
32mod algorithm;
33mod controller;
34mod future;
35mod layer;
36mod service;
37mod vegas;
38
39pub use self::algorithm::Algorithm;
40pub use self::layer::ConcurrencyLimitLayer;
41pub use self::service::ConcurrencyLimit;
42pub use self::vegas::Vegas;