Skip to main content

Module memory_limit

Module memory_limit 

Source
Expand description

Aggregate memory admission for gRPC services.

Tonic decompresses and decodes a complete request message (up to max_recv_message_size, 512 MiB by default) before the typed handler is invoked, so a handler that charges the ServerMemoryLimiter only sees the request after the memory is already allocated. For transport-compressed messages (grpc-encoding: gzip/zstd) a few KiB on the wire can expand to hundreds of MiB during that window, which would bypass any aggregate quota.

MemoryLimiterExtensionLayer therefore reserves the configured maximum decoded message size for every compressed request before the inner (tonic) service runs, and holds the reservation for the whole request. Handlers can detect the reservation via PreDecodeMemoryReservation in the request extensions and skip their own post-decode charge to avoid double accounting.

The reservation is intentionally conservative (it upper-bounds the decoded size before it is known); with the default unlimited limiter it is a no-op.

Structs§

MemoryLimiterExtensionLayer
MemoryLimiterExtensionService
PreDecodeMemoryReservation 🔒
Present in the request extensions when memory for the (compressed) request’s decoded message was reserved before tonic decompression.

Constants§

GRPC_ENCODING_HEADER 🔒
The gRPC request compression selector header.
IDENTITY_ENCODING 🔒
The “no compression” encoding value.