[Issue #1391] Set the gunicorn workers based on CPU count #1476
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.
Summary
Fixes #1391
Time to review: 3 mins
Changes proposed
Set the number of gunicorn workers to 2*cpu count + 1
Context for reviewers
We temporarily set the number of workers to exactly 2 while getting the API running initially. This shouldn't be needed anymore, and would mean we are potentially underutilitizing our API instances. This number follows the recommended values:
See: https://docs.gunicorn.org/en/stable/design.html#how-many-workers
also: https://docs.gunicorn.org/en/latest/configure.html#configuration-file
Currently, we run 2 workers always. With our current API configuration, this should change to 5. We actually log the
sched_getaffinity
value when the process starts up. Pulling from the prod logs, this gives (trimming extra info for brevity):The
cpu_usable
metric is just thelen(sched_getaffinity(0))
value: https://github.com/HHS/simpler-grants-gov/blob/main/api/src/logging/config.py#L140Additional information
To test this, you need to adjust the docker-compose file to run the following command:
["poetry", "run", "gunicorn", "src.app:create_app()"]
That'll create several workers, which run uneventfully locally, but produce a lot of logs.