Skip to main content

Crate tower_acc

Crate tower_acc 

Source
Expand description

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

use tower::ServiceBuilder;
use tower_acc::{ConcurrencyLimitLayer, Vegas};

let service = ServiceBuilder::new()
    .layer(ConcurrencyLimitLayer::new(Vegas::default()))
    .service(my_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.

Structs§

Aimd
AIMD (Additive Increase / Multiplicative Decrease) concurrency limit strategy.
ConcurrencyLimit
Enforces an adaptive limit on the concurrent number of requests the underlying service can handle.
ConcurrencyLimitLayer
A Layer that wraps services with an adaptive ConcurrencyLimit.
DefaultClassifier
The default classifier: treats every Err as a server error.
Gradient2
Netflix Gradient2–inspired adaptive concurrency limit strategy.
Vegas
TCP Vegas–inspired adaptive concurrency limit strategy.

Traits§

Algorithm
An algorithm that dynamically adjusts the maximum number of allowed concurrent requests based on the observed traffic.
Classifier
Inspects the result of a service call to determine whether the outcome should be treated as a server error for concurrency-control purposes.