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

[Issue #1391] Set the gunicorn workers based on CPU count #1476

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions api/gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
# We use 'os.sched_getaffinity(pid)' not 'os.cpu_count()' because it returns only allowable CPUs.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesbursa I was curious on your opinion of how we use gunicorn compared to past projects.

Past projects we setup gunicorn in our main function, while here we tell gunicorn to run our app via a specific create_app function. This means all of the code that runs in that create_app function is run extra times for each worker. That means code like logging initialization duplicates. This doesn't seem to cause any issues at the moment, but does make the initialization a bit confusing.

# os.sched_getaffinity(pid): Return the set of CPUs the process with PID pid is restricted to.
# os.cpu_count(): Return the number of CPUs in the system.
# workers = len(os.sched_getaffinity(0)) * 2

# Until we figure out better math, ignore the above. Hardcoding # workers because Python gets EC2 CPU not Fargate
# 1 vCPU is equivalent to 1 core of a hyperthreaded processor, which will give you 1 physical core & 2 threads
workers = 2
workers = (len(os.sched_getaffinity(0)) * 2) + 1
threads = 4
Loading