簡體   English   中英

如何更改uwsgi(nginx + django)應用程序重新加載模式以減少首次請求的重新加載/等待延遲

[英]How to change uwsgi(nginx+django) app reload mode to decrease reload/wait latency for first request

嘗試減少第一次請求的重新加載/等待時間時遇到問題。

我使用的是nginx 1.7,uwsgi 2.0.4,django 1.6。 一開始,我發現第一個請求非常慢,並且從日志中發現,這是因為為第一個請求加載了應用程序。 因此,我在Google上搜索了很多,並嘗試更改uwsgi重新加載模式。

我想使用惰性應用程序模式來減少延遲。 但是,總是會遇到錯誤。

uwsgi配置:

<uwsgi>
  <socket>/var/run/uwsgi.socket</socket>
  <listen>100</listen>
  <master>true</master>
  <vhost>true</vhost>
  <no-site>true</no-site>
  <pidfile>/usr/local/nginx/uwsgi.pid</pidfile>
  <processes>8</processes>
  <profiler>true</profiler>
  <memory-report>true</memory-report>
  <enable-threads>true</enable-threads>
  <logdate>true</logdate>
  <lazy-apps>true</lazy-apps>
  <touch-chain-reload>true</touch-chain-reload>
  <limit-as>6048</limit-as>
  <daemonize>/home/django.log</daemonize>
</uwsgi>

這是nginx的配置:

server {
        listen  80;
        server_name xxx.com;
        location / {
            uwsgi_pass   unix:///var/run/uwsgi.socket;
            include     uwsgi_params;
            uwsgi_param UWSGI_CHDIR /home/test;
            uwsgi_param UWSGI_SCRIPT wsgi;
           access_log  off;
        }
        location /static/ {
        root            /home/test/;
        access_log      off;
        log_not_found   off;
        autoindex on;
    }
 }

但似乎沒有任何變化,請在此處登錄:

[root@localhost ~]# tail -f /home/django.log
Wed Sep  2 11:45:55 2015 - spawned uWSGI worker 7 (pid: 23818, cores: 1)
Wed Sep  2 11:45:55 2015 - spawned uWSGI worker 8 (pid: 23819, cores: 1)
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***
Wed Sep  2 11:45:55 2015 - *** no app loaded. going in full dynamic mode ***

仍然只有在第一個請求到來時應用程序才會加載,並且延遲增加到將近7秒。 我的配置錯誤嗎? 還是不應該使用惰性應用程序? 如果是這樣,還有什么其他方式適合我的情況?

謝謝。 衛斯理

您似乎沒有用於加載應用程序的任何配置選項。 使用wsgi-filemodule選項導入您的應用程序,並設置need-app以阻止uwsgi從空開始。

<wsgi-file>myproject/wsgi.py</wsgi-file>

要么

<module>myproject.wsgi</module>

使用lazy-apps會使每個工作人員分別加載應用程序,這可能不是您想要的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM