Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task]: Modify gunicorn config to use recommended number of workers and threads #1391

Closed
1 task
chouinar opened this issue Mar 1, 2024 · 0 comments · Fixed by #1476
Closed
1 task

[Task]: Modify gunicorn config to use recommended number of workers and threads #1391

chouinar opened this issue Mar 1, 2024 · 0 comments · Fixed by #1476
Assignees
Labels
project: grants.gov Grants.gov Modernization tickets

Comments

@chouinar
Copy link
Collaborator

chouinar commented Mar 1, 2024

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

  • Number of workers is 2*cpu + 1
@chouinar chouinar added the project: grants.gov Grants.gov Modernization tickets label Mar 1, 2024
@chouinar chouinar added this to the API - Enhancements milestone Mar 1, 2024
@chouinar chouinar self-assigned this Mar 13, 2024
chouinar added a commit that referenced this issue Mar 14, 2024
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: grants.gov Grants.gov Modernization tickets
Projects
Development

Successfully merging a pull request may close this issue.

1 participant