feat(proxy): reject at capacity instead of queueing unboundedly#143
Merged
Conversation
When an app's ProxyDeployment semaphore is full, the deployment function
now raises RuntimeError("...has reached its maximum of N concurrent
requests and is currently very busy. Please try again in a moment.")
instead of awaiting a free slot.
A blocked caller holds its already-decoded payload (e.g. an inference
image) in the proxy actor's memory while it waits, so an open-ended
queue grows proxy memory without bound. Failing fast returns capacity
pressure to the caller and frees the payload immediately. The cap is the
existing per-app max_ongoing_requests knob; behaviour changes from
"queue when full" to "reject when full" for every app.
.locked() is race-free here: because we reject rather than await, the
semaphore never accumulates waiters, and there is no await between the
check and the acquire.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The "maximum of N concurrent requests" wording already conveys that the app is at capacity; the extra "currently very busy" was redundant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nilsmechtel
marked this pull request as ready for review
July 16, 2026 09:03
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
When an app's
ProxyDeploymentsemaphore is full, the per-method proxy function now raises aRuntimeErrortelling the caller the app is at capacity, instead of silently awaiting a free slot.The cap is the existing per-app
max_ongoing_requestsknob (deploy-timedeploy_app(max_ongoing_requests=…), default 10; decorator default@bioengine.app(max_ongoing_requests=…)). No new parameter.Why
Every user call (WebSocket + WebRTC) funnels through
deployment_function, which heldasync with self.service_semaphore. When full, request N+1 awaited a slot — an unbounded queue of coroutines, each already holding its decoded payload (e.g. an inference image) in the proxy actor's memory. Under load this grows proxy memory without bound and gives the caller no signal. Failing fast returns capacity pressure to the caller and frees the payload immediately.Behaviour changes from "queue when full" to "reject when full" for every app. It does not touch the inner Entry/Runtime deployments' own Ray Serve
max_ongoing_requests(the autoscaling-signal queue) — only the proxy's Hypha-facing semaphore.Safety
.locked()is race-free here: because we reject rather than await, the semaphore never accumulates waiters, so.locked()reduces to "no free slot", and there is noawaitbetween the check and the acquire.Validation
Deployment-side change → validated on a dev image on a live cluster before marking ready (deploy an app with
max_ongoing_requests=1, fire concurrent calls, confirm the excess returns the busyRuntimeErrorwhile in-flight calls still succeed).🤖 Generated with Claude Code