You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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):
```json
{
"name": "src.logging.config",
"levelname": "INFO",
"levelno": 20,
"pathname": "/api/src/logging/config.py",
"funcName": "log_program_info",
"cpu_count": 2,
"cpu_usable": 2,
"message": "start src: CPython 3.12.2 Linux, hostname ip-10-3-0-56.ec2.internal, pid 7, user 1001(runner)"
}
```
The `cpu_usable` metric is just the `len(sched_getaffinity(0))` value:
https://github.com/HHS/simpler-grants-gov/blob/main/api/src/logging/config.py#L140
## Additional 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.
Summary
While we were getting the API stabilized, we hardcoded the number of workers rather than have it scale off of the CPU. We should fix that.
See: https://docs.gunicorn.org/en/stable/design.html#how-many-workers
also: https://docs.gunicorn.org/en/latest/configure.html#configuration-file
Acceptance criteria
The text was updated successfully, but these errors were encountered: