简体   繁体   中英

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

I hit a problem when trying to decrease reloading/waiting time for first request.

I use nginx 1.7, uwsgi 2.0.4, django 1.6. In the beginning, I find the first request is very slow, and from the log, due to app loaded for the first request. So, I googled a lot and trying to change the uwsgi reload mode.

I wannted to use lazy-apps mode to decrease the latency. But, always hit errors.

uwsgi config:

<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>

Here is nginx config:

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;
    }
 }

But seems nothing changed, log here:

[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 ***

Still app only loaded when first request comes and latency increases to almost 7 seconds. is my configuraton wrong? Or shouldn't use lazy-apps? If then, what else mode suits my situation?

Thanks. Wesley

You don't seem to have any configuration options for loading your application. Use wsgi-file or module option to import your application, and set need-app to stop uwsgi from starting empty.

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

or

<module>myproject.wsgi</module>

Using lazy-apps makes each worker load the application separately, which might not be what you want .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM