-
Notifications
You must be signed in to change notification settings - Fork 13
/
gunicorn.conf.py
26 lines (19 loc) · 1021 Bytes
/
gunicorn.conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Configuration file for the Gunicorn server used to run the application in production environments.
Attributes:
bind(str): The socket to bind. Formatted as '0.0.0.0:$PORT'.
workers(int): The number of worker processes for handling requests.
threads(int): The number of threads per worker for handling requests.
For more information, see https://docs.gunicorn.org/en/stable/configure.html
"""
import os
from src.app_config import AppConfig
app_config = AppConfig()
bind = app_config.host + ':' + str(app_config.port)
# Calculates the number of usable cores and doubles it. Recommended number of workers per core is two.
# https://docs.gunicorn.org/en/latest/design.html#how-many-workers
# We use 'os.sched_getaffinity(pid)' not 'os.cpu_count()' because it returns only allowable CPUs.
# 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) + 1
threads = 4