Derive RoadRunner worker defaults from the container CPU limit - #2662
Closed
torvalstrom wants to merge 1 commit into
Closed
torvalstrom wants to merge 1 commit into
torvalstrom wants to merge 1 commit into
Conversation
RoadRunner resolves num_workers: 0 against the number of CPUs the host reports, which is unaffected by any CPU limit set on the container. On a 24-core host with the container limited to 1 CPU that starts 24 web plus 24 task workers, at roughly 50-60MB each, so the container idles around 1.2GB before serving a request and 48 of those workers can never run concurrently. When a CPU limit is present, derive the defaults from it instead. Without a limit nothing changes, and an explicitly set WEB_WORKER_NUM or TASK_WORKER_NUM still wins. Web workers get a floor of 2 so that a single slow request cannot block the whole container when the limit is one CPU. Refs shlinkio#2661
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.
Fixes the default worker count described in #2661.
RoadRunner resolves
num_workers: 0against the number of CPUs the hostreports, which is unaffected by a CPU limit set on the container. On a 24-core
host with the container limited to 1 CPU that is 24 web + 24 task workers at
~50-60MB each — about 1.2GB before a single request is served, and 48 workers
that can never run concurrently.
This reads the cgroup CPU quota in the entrypoint and derives the defaults from
it. Behaviour is unchanged when there is no CPU limit, and an explicitly set
WEB_WORKER_NUM/TASK_WORKER_NUMstill wins.Web workers get a floor of 2, so a single slow request cannot block the whole
container when the limit is one CPU. Happy to drop that floor if you would
rather keep strict one-per-CPU.
Tested
Both cgroup v1 and v2 paths are read; verified in
busybox sh(alpine:3.20) anddash(debian:12-slim):--cpus=0.5--cpus=1--cpus=3--cpus=4--cpus=1 -e WEB_WORKER_NUM=9On the instance that prompted #2661, setting these by hand took the same
container from 50 processes / 1262MB to 7 / 183MB with no change in behaviour.
If you would rather solve this with documentation than with a behaviour change,
I am happy to convert this into a docs PR instead.