Prometheus remote_write timeout and retry bounds for memory-constrained environments
0 reputation · 30 Jan 2020, 13:51 UTC
0 reputation · 30 Jan 2020, 13:51 UTC
Prometheus remote_write accepts a remote endpoint URL and queue configuration, but as of version 2.54 the HTTP client used for write requests does not expose a configurable timeout. When a remote storage endpoint becomes unresponsive, the client may block indefinitely rather than aborting after a fixed duration.
The retry logic for failed writes also appears to continue without a documented maximum attempt count or backoff ceiling. Under sustained network partitions or backend outages, the internal send queue can grow as samples accumulate faster than they drain, which may lead to observable memory pressure. The exact threshold varies with sample volume and shard count.
Because the absence of a timeout may be intentional for use cases requiring persistent delivery, it is unclear whether operators should rely on external proxy timeouts or whether a native configuration option is planned.
What is the intended behavior for remote_write request timeouts in Prometheus 2.54, and is there a supported way to cap retry attempts or queue memory? If no native timeout exists, what configuration boundaries are recommended to prevent unbounded memory pressure during remote endpoint failures?
34775 reputation · 31 Jan 2020, 00:02 UTC
In Prometheus 2.54, there is no native, granular configuration option to set a specific HTTP request timeout for remote_write. The system is designed for persistent delivery, meaning it prioritizes the eventual transmission of samples over strict request deadlines. Consequently, if a remote endpoint accepts a connection but stops responding, the client may block, and the internal retry logic will continue to attempt delivery using an exponential backoff mechanism.
While you cannot cap the retry count or set a native timeout, you can prevent Out-of-Memory (OOM) events by strictly bounding the remote_write queue. Memory pressure during backend outages is a function of the queue capacity and the number of shards. When the queue reaches its limit, Prometheus performs a "head-drop," discarding the newest samples to protect the process memory.
To cap memory usage, configure the following parameters in your remote_write configuration block:
capacity: This is the most critical setting for memory constraints. It defines the maximum number of samples queued per shard. Total potential samples in memory = capacity × max_shards.max_shards: Limit the number of parallel senders to reduce the multiplier effect on the capacity setting.max_samples_per_send: Adjust this to control the batch size of each request, which influences the memory footprint of individual outgoing buffers.If your environment requires strict request timeouts to prevent blocking, the supported architectural pattern is to deploy a sidecar proxy (such as Envoy or Nginx) between Prometheus and the remote endpoint. The proxy can be configured to enforce a hard request_timeout, returning a 5xx error to Prometheus, which then triggers the standard retry/backoff logic rather than hanging indefinitely.
To verify if your queue boundaries are sufficient or if you are losing data due to memory caps, monitor the following Prometheus metrics:
# Rate of samples dropped due to queue being full
rate(prometheus_remote_storage_samples_dropped_total[5m])
# Current number of samples queued
prometheus_remote_storage_samples_queued
Diagnostic Detail Needed: Please provide the current capacity and max_shards values in your configuration. If these are left at defaults, the memory footprint may be significantly higher than anticipated for high-cardinality workloads.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.