Reputation: 122
I'm using uwsgi + django and trying to make the fastest reloading. I've configured chain reloading (http://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#chain-reloading-lazy-apps), but still there are couple seconds of latency while serving first request after worker reload.
Is there any way to warm up the django application with uwsgi configuration to reduce waiting time?
Upvotes: 5
Views: 1417
Reputation: 4130
In the cited article, there is an special recommendation for Django and so apps: http://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#dealing-with-ultra-lazy-apps-like-django
On some of my projects, there are a /warmup/
URL that loads everything that can be loaded upfront. The uWSGI does give client requests to the worker only after the whole wsgi.py
of the project ran, so we do a fake call the /warmup/
url BEFORE the uWSGI tried to serve any real client requests:
# /django-project-root/wsgi.py
import sys
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
(...)
# Django warm-up ahead of time instead of lazy
# From: http://uwsgi-docs.readthedocs.org/en/latest/articles/TheArtOfGracefulReloading.html#dealing-with-ultra-lazy-apps-like-django
# And: https://github.com/stefantalpalaru/uwsgi_reload/blob/master/examples/wsgi.py#L19
application({
'REQUEST_METHOD': 'GET',
'SERVER_NAME': '127.0.0.1',
'SERVER_PORT': 80,
'PATH_INFO': '/warmup/',
'wsgi.input': sys.stdin,
}, lambda x, y: None)
Please mind that if your uwsgi.ini
configures lazy-apps=true
then the process load will trigger only on client requests, so it will warmup only in case of an harakiri
. Otherwise it will warmup fine.
Upvotes: 9