Cap the number of requests in the image stage - #109
Closed
beetlebugorg wants to merge 1 commit into
Closed
Conversation
- Add DimsMaxInFlight. The default 0 keeps no limit. - Count in-flight requests in shared memory, across every worker. - Refuse a request over the cap with 503 before it does image work.
Owner
Author
|
The Apache event MPM already bounds concurrent requests per child at ThreadsPerChild, and server-wide at ServerLimit times ThreadsPerChild. That bound is self-healing: a killed child releases its threads with it. A per-child DimsMaxInFlight that spans the whole handler duplicates that bound. A server-wide shared counter does not duplicate it, but a child that is killed while it holds a slot leaks the slot. The count then drifts up until every request returns 503, and only a restart clears it. That failure appears under the same memory pressure the cap exists to handle. The shipped container sizes ThreadsPerChild, ServerLimit, and the ImageMagick memory limits instead. A soak test under a fixed CPU and memory limit sets the numbers. |
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
Add
DimsMaxInFlight. It caps the number of requests in the image stage at once, across every worker process. A request over the cap returns 503 before any image work. The default is 0, which means no limit and reproduces today's behavior.Why
The number of requests decoding at once equals the worker count. Each one can hold a full pixel cache, so a burst exhausts memory. A server-wide cap bounds the concurrent pixel caches independent of the worker count. Over the cap, the server returns 503 without decoding.
The counter lives in the shared memory block that already holds the request counters. The handler takes a slot after verification and before the fetch, so the fetch buffer and the pixel cache are both covered.
dims_send_imageanddims_cleanuprelease the slot, guarded by a per-request flag, so every exit path releases exactly once.Verify
All 268 cases pass.
TestOverTheCapIsRefusedstarts a slow request that holds the only slot on the port 8008 server, confirms a second request returns 503, then confirms an ordinary request is served again after the slot frees.No module allocation is definitely lost.
Breaking
Nothing. The default is no cap.