Expand description
Per-service concurrency limiting for gRPC servers.
Unlike [tower::limit::GlobalConcurrencyLimitLayer] applied around a whole
server, ServiceConcurrencyLimit bounds the in-flight requests of a
single gRPC service, so services sharing one listener cannot crowd each
other out of admission slots.
Tower’s per-service [tower::limit::ConcurrencyLimitLayer] cannot be used
here: its ConcurrencyLimit wrapper does not implement tonic’s
[NamedService], which Routes::add_service requires for routing, and
shedding through tower’s LoadShed surfaces as a BoxError, incompatible
with the router’s Error = Infallible bound — over-limit requests must be
answered in-band with a gRPC RESOURCE_EXHAUSTED response instead.
Structs§
- Permit
Guarded Body - Response body owning a guard, typically a semaphore permit, that is released when the body is dropped: once the response has been written, reset, or abandoned.
- Reclaimable
Body - Response body that gives up its contents when a deadline passes before
it has been sent. The transport polls a body only when the receiver
grants it window, so a receiver that stops reading leaves the body
parked, together with everything it owns; the deadline takes the inner
body and
until_deadlineaway from under it, and any later poll yields an error.until_endstays until the body itself is dropped, once the stream has been written, reset or abandoned. - Service
Concurrency Limit - Bounds the number of concurrent in-flight requests to the wrapped gRPC service, independently of any other service registered on the same server.