diff --git a/Dockerfile b/Dockerfile index e25d95cd44..09191c73c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,10 +19,4 @@ RUN cp /antares-launcher/requirements.txt /conf/antares-launcher/requirements.tx RUN pip3 install --upgrade pip \ && pip3 install -r /conf/requirements.txt -ENTRYPOINT uvicorn \ - --workers $UVICORN_WORKERS \ - --root-path $UVICORN_ROOT_PATH \ - --timeout-keep-alive $UVICORN_TIMEOUT \ - --host 0.0.0.0 \ - --port 5000 \ - antarest.wsgi:app \ No newline at end of file +ENTRYPOINT gunicorn --config /conf/gunicorn.py --worker-class=uvicorn.workers.UvicornWorker antarest.wsgi:app diff --git a/conf/gunicorn.py b/conf/gunicorn.py new file mode 100644 index 0000000000..ebf16122c1 --- /dev/null +++ b/conf/gunicorn.py @@ -0,0 +1,30 @@ +# Reference: https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py + +import multiprocessing +import os + +bind = "0.0.0.0:5000" + +""" +Gunicorn relies on the operating system to provide all of the load balancing +when handling requests. Generally we recommend (2 x $num_cores) + 1 +as the number of workers to start off with. While not overly scientific, +the formula is based on the assumption that for a given core, +one worker will be reading or writing from the socket +while the other worker is processing a request. +https://docs.gunicorn.org/en/stable/design.html#how-many-workers +""" + +workers = os.getenv("GUNICORN_WORKERS") +if workers == "ALL_AVAILABLE" or workers is None: + workers = multiprocessing.cpu_count() * 2 + 1 + +timeout = 10 * 60 # 10 minutes +keepalive = 24 * 60 * 60 # 1 day + +capture_output = True + +loglevel = "info" +errorlog = "-" +accesslog = "-" +preload_app = False \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9b64f12db6..2079761a07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,4 +22,5 @@ starlette~=0.14.2 locust~=1.5.1 MarkupSafe~=1.1.1 checksumdir~=1.2.0 -pydantic~=1.8.2 \ No newline at end of file +pydantic~=1.8.2 +gunicorn \ No newline at end of file