From 0852e59c091f8711e9e132e3c1aec39ce3e828eb Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Thu, 26 Nov 2026 04:15:41 +0000 Subject: [PATCH] docs(shared-state): say long streams drop out of the in-flight count The request timeout is progress-based, so a stream that keeps sending data can outlive the in-flight read window. It then drops out of the shared count. The count can only be too low for such streams. --- README.md | 2 +- shared_state_wire.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66e0b3a..f1ced9f 100644 --- a/README.md +++ b/README.md @@ -741,7 +741,7 @@ How it works: - A breaker counts consecutive failures across all replicas. A success on any replica resets the count and closes an open breaker. The replica whose flush takes the count from below the threshold to the threshold or above opens the breaker for all replicas. Open times and thresholds are the local ones: 3 failures and 30 seconds, doubling to 5 minutes, for the request breaker; the `breaker` block for the discovery breaker; 3 failures and 30 seconds for the decision breaker. - A breaker reads as open when its local breaker or the shared breaker is open. - With `redis.sharedState` on, the discovery `breaker.failureThreshold` counts failed refreshes across every route instance of every replica, not consecutive failures on one instance. Each instance runs its own discovery loop and adds each failed refresh to the shared count. Any success on any instance resets the count. The count also expires after twice `breaker.maxOpenDuration`. With the default threshold of `3` and several instances, a single round of failed refreshes can open the shared breaker. Raise `failureThreshold` for a large fleet. The local breaker of each instance still counts consecutive failures on that instance. -- In-flight load is the larger of the local count and the shared count. A request that never ends stops counting after its start epoch leaves the read window. The window is the longest request timeout in 5 minute epochs, plus one epoch. +- In-flight load is the larger of the local count and the shared count. The read window is the longest request timeout in 5 minute epochs, plus one epoch. A request stops counting when its start epoch leaves the window. A request timeout is progress-based: a stream that keeps sending data can run longer than the timeout. Such a stream drops out of the shared count when the window passes, so the shared count can be too low for long streams. It is never too high because of them. - The request path never calls Redis. It reads a local copy. A background loop sends the counts and refreshes the copy every second, so a change on one replica reaches the others in about 1 second. The token-size estimate refreshes every 60 seconds with the router learning loop, and it applies after 50 shared samples. - A Redis outage never fails or slows a request, and `redis.failOpen` does not apply to this state. After 3 failed refreshes in a row the gateway drops the shared values and uses its own local state. A failed token-size refresh keeps the last ratios. - While you change the switch on a rolling restart, replicas with the switch off write nothing. Counts can then be too low for a short time. Turn the switch on after the code is deployed on every replica. diff --git a/shared_state_wire.go b/shared_state_wire.go index ca63eae..7418964 100644 --- a/shared_state_wire.go +++ b/shared_state_wire.go @@ -31,7 +31,8 @@ func (g *Gateway) wireSharedState(cfg *Config) { } } -// maxProviderTimeout is the longest request timeout any provider can run, which bounds how long an in-flight count stays live. +// maxProviderTimeout is the longest request timeout any provider has, which sets the in-flight read window. +// The timeout is progress-based, so a stream can outlive it and drop out of the count: an under-count only. func maxProviderTimeout(cfg *Config) time.Duration { global, err := resolveRequestTimeout(cfg.RequestTimeout, "requestTimeout") if err != nil {