gpt4 book ai didi

django - 公开之前如何预热Django Web服务?

转载 作者:行者123 更新时间:2023-12-02 18:27:32 29 4
gpt4 key购买 nike

我正在AWS ecs上运行Django Web应用程序。

我想在部署新版本时预热服务器(命中第一个请求,并且Django需要花费一些时间来加载)。

在将服务器注册到应用程序负载平衡器之前,是否可以预热服务器?

  • 编辑

  • 我正在使用Nginx + uwsgi

    最佳答案

    我假设您使用mod_wsgi,因为这是here描述的行为:

    Q: Why do requests against my application seem to take forever, but then after a bit they all run much quicker?

    A: This is because mod_wsgi by default performs lazy loading of any application. That is, an application is only loaded the first time

    that a request arrives which targets that WSGI application. This means that those initial requests will incur the overhead of loading all the application code and performing any startup initialisation.

    This startup overhead can appear to be quite significant, especially if using Apache prefork MPM and embedded mode. This is

    because the startup cost is incurred for each process and with prefork MPM there are typically a lot more processes that if using worker MPM or mod_wsgi daemon mode. Thus, as many requests as there are processes will run slowly and everything will only run full speed once code has all been loaded.

    Note that if recycling of Apache child processes or mod_wsgi daemon processes after a set number of requests is enabled, or for

    embedded mode Apache decides itself to reap any of the child processes, then you can periodically see these delayed requests occurring.

    Some number of the benchmarks for mod_wsgi which have been posted do not take into mind these start up costs and wrongly try to compare

    the results to other systems such as fastcgi or proxy based systems where the application code would be preloaded by default. As a result mod_wsgi is painted in a worse light than is reality. If mod_wsgi is configured correctly the results would be better than is shown by those benchmarks.

    For some cases, such as when WSGIScriptAlias is being used, it is actually possible to preload the application code when the processes

    first starts, rather than when the first request arrives. To preload an application see the WSGIImportScript directive.



    我认为您可以尝试使用 WSGIScriptAlias查看更多 here

    关于django - 公开之前如何预热Django Web服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58129143/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com