【问题标题】:Warmup django application during uwsgi chain-raload在 uwsgi chain-raload 期间预热 django 应用程序
【发布时间】:2017-06-15 00:52:36
【问题描述】:

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

有没有什么方法可以通过 uwsgi 配置来预热 django 应用程序以减少等待时间?

【问题讨论】:

    标签: python django reload uwsgi


    【解决方案1】:

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

    在我的一些项目中,有一个/warmup/ URL 可以加载可以预先加载的所有内容。 uWSGI 确实在整个项目的wsgi.py 运行之后才向工作人员发出客户端请求,所以我们在 uWSGI 尝试服务任何真实的客户端请求之前对/warmup/ 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)
    

    请注意,如果您的 uwsgi.ini 配置了 lazy-apps=true,那么进程加载将仅在客户端请求时触发,因此只有在 harakiri 的情况下才会预热。否则它会正常预热。

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 2012-04-13
      • 1970-01-01
      相关资源
      最近更新 更多