fix(chart): cap per-pod backend concurrency at the frontproxy (maxconn)#99
Merged
Conversation
The remaining concurrent-backup OOM is below the app's memory limiter: uvicorn buffers each in-flight request body off the socket BEFORE our limiter runs, so a backup flood piles up request bodies in the HTTP server's C-level buffers (the governor reads ~64MB while RSS hits 512Mi+ -> OOMKilled, exit 137). This memory is invisible and ungovernable from the app layer. The load balancer is the right place to bound it. haproxy had only a global maxconn (4096) and no per-pod cap, so it could dump 100+ concurrent connections onto a single pod. Add `maxconn` per backend server (default 40) plus `timeout queue`: haproxy now caps in-flight requests per pod and QUEUES the excess (redispatching to a less-loaded pod) instead of overrunning one pod's uvicorn buffers. The app's existing limiter then governs the admitted few. Verified locally at prod config (512Mi cap, 64MB budget, 2026.6.14 app): - direct 128x16MB PUT flood -> OOMKilled exit 137 (reproduces prod) - same flood via haproxy maxconn 40 -> 256/256 ok, pod peaks 335MiB, no OOM - harsh mixed upload+GET flood via haproxy -> 322MiB, no OOM haproxy queues rather than rejects, so clients mostly see success, not 503s. Validated the rendered haproxy.cfg with `haproxy -c` (exit 0).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Cap per-pod backend concurrency at the frontproxy (haproxy
maxconn) to stop the concurrent-backup OOM that lives below the app's memory limiter.Why the app limiter can't fix this
uvicorn buffers each in-flight request body off the socket before our memory limiter runs. Under a backup flood, request bodies pile up in the HTTP server's C-level buffers — the governor reads ~64MB while RSS hits 512Mi+ and the pod is OOMKilled (exit 137). That memory is invisible and ungovernable from the app layer.
Profiler confirmed it: peak RSS 957MiB but only 87MB Python-tracked — the rest is uvicorn/httptools socket buffers for ~125 concurrent bodies.
The fix
haproxy had only a global
maxconn 4096and no per-pod cap, soleastconncould still dump 100+ connections onto one pod. This adds:haproxy now bounds in-flight requests per pod and queues the excess (redispatching to a less-loaded pod) instead of overrunning a pod's uvicorn buffers. The app's existing limiter governs the admitted few. Both knobs are chart values (
frontproxy.maxConnPerPod,frontproxy.timeouts.queue).Why the LB, not uvicorn
--limit-concurrencyProof (local, prod config: 512Mi cap / 64MB budget / 2026.6.14 app)
maxconn 40Rendered
haproxy.cfgvalidated withhaproxy -c(exit 0).Scope
This is the upload-side OOM (the dominant cause on 2026.6.14, kill windows were PUT-heavy). Stacks on: