在 uwsgi chain-raload 期间预热 django 应用程序

Ale*_*sky 5 python django reload uwsgi

我正在使用 uwsgi + django 并试图使重新加载速度最快。我已经配置了链重新加载(http://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#chain-reloading-lazy-apps),但在服务第一个请求时仍然有几秒钟的延迟工人重新加载后。

有没有办法用uwsgi配置来预热django应用程序以减少等待时间?

ala*_*jds 7

在引用的文章中,有对 Django 等应用的特别推荐:http : //uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#dealing-with-ultra-lazy-apps-like-姜戈

在我的一些项目中,有一个/warmup/URL 可以加载可以预先加载的所有内容。只有在整个wsgi.py项目运行后,uWSGI 才会向工作人员发出客户端请求,因此我们/warmup/在 uWSGI 尝试为任何真实的客户端请求提供服务之前假调用url:

# /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)
Run Code Online (Sandbox Code Playgroud)

请注意,如果您进行了uwsgi.ini配置,lazy-apps=true那么进程负载只会在客户端请求时触发,因此它只会在harakiri. 否则它会很好地预热。