Docker: Running a Flask app via Gunicorn - Worker timeouts? Poor performance? Docker: Running a Flask app via Gunicorn - Worker timeouts? Poor performance? flask flask

Docker: Running a Flask app via Gunicorn - Worker timeouts? Poor performance?


I managed to find this helpful article which explains why Gunicorn hangs.https://pythonspeed.com/articles/gunicorn-in-docker/

The solution for me was to change the worker temp directory and increase the minimum workers to 2. I still see workers being killed off but there is no longer any delays / slowness. I suspect adding in the gthread will improve things further.

Here is my updated Dockerfile:

FROM python:3.6.9-slim# Copy all the files to the src folderCOPY build/ /usr/src/# Create the virtual environmentRUN python3 -m venv /usr/src/myapp_venv# Install the requirementsRUN /usr/src/myapp_venv/bin/pip3 install -r /usr/src/requirements.txt# Runs gunicorn# --chdir sets the directory where gunicorn should look for the server files# server:app means run the "server.py" file and look for the "app" constructor within thatENTRYPOINT ["/usr/src/myapp/bin/gunicorn", "--bind", "0.0.0.0:5000", "--worker-tmp-dir", "/dev/shm", "--workers", "2", "--chdir", "/usr/src/", "server:app"]# Expose the gunicorn portEXPOSE 5000