I have a Django app. It uses Nginx, sits on an EC2 instance, and uses an AWS load balancer in front of that. Nginx serves static files right from disk as well as using proxy_pass
for everything else to route to the WSGI app server.
It is the choice of WSGI server that I'm seeing puzzling results for.
When I use Django's development server, ./manage.py runserver 0.0.0.0:8000
, the average response time for the resulting HTML document at /
is 60-70 ms:
Blocked: 1 ms
DNS resolution: 0 ms
Connecting: 0 ms
TLS setup: 0 ms
Sending: 0 ms
Waiting: 68 ms
Receiving: 0 ms
Now when I replace this with a "proper" Gunicorn server, the average response time for the same request/doc is now 1800 ms!
Blocked: 1 ms
DNS resolution: 0 ms
Connecting: 0 ms
TLS setup: 0 ms
Sending: 0 ms
Waiting: 1859 ms
Receiving: 0 ms
Here I'm running Gunicorn as:
gunicorn \
--log-level DEBUG \
--bind 0.0.0.0:8000 \
--workers 4 \
project.wsgi
The same exact thing goes for uwsgi, with an average reponse time of 1850 ms:
uwsgi --chdir=/home/ubuntu/project \
--module=project.wsgi:application \
--env DJANGO_SETTINGS_MODULE=project.settings \
--master \
--http-socket 0.0.0.0:8000 \
--processes=5 \
--max-requests=5000 \
--vacuum
And, notably, the response time does not change regardless of whether the number of workers is much higher e.g. --workers 64
(nor would I expect it to, since this is not about concurrent requests).
What would likely account for this difference? Am I falling for some common pitfall?
Versions:
$ python -m django --version
2.2.6
$ gunicorn --version
gunicorn (version 19.9.0)
$ nginx -v
nginx version: nginx/1.14.0 (Ubuntu)