Skip to content

Commit

Permalink
Use gunicorn
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Bui-Quang <[email protected]>
  • Loading branch information
pl-buiquang committed Jul 12, 2021
1 parent 2ec766f commit 4f284bc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
ENTRYPOINT gunicorn --config /conf/gunicorn.py --worker-class=uvicorn.workers.UvicornWorker antarest.wsgi:app
30 changes: 30 additions & 0 deletions conf/gunicorn.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ starlette~=0.14.2
locust~=1.5.1
MarkupSafe~=1.1.1
checksumdir~=1.2.0
pydantic~=1.8.2
pydantic~=1.8.2
gunicorn

0 comments on commit 4f284bc

Please sign in to comment.