附上对比
benchmark.png

来源UWSGI VS. GUNICORN, OR HOW TO MAKE PYTHON GO FASTER THAN NODE

使用pip镜像

编辑 ~/.pip/pip.conf

   [global]
   index-url=https://pypi.tuna.tsinghua.edu.cn/simple/

*windows*
编辑 %APPDATA%\pip\pip.ini
    [global]
    timeout = 6000
    index-url = http://pypi.douban.com/simple
    trusted-host = pypi.douban.com

更新依赖

pip install uwsgi

编辑配置文件 uwsgi.ini

[uwsgi]
# Django-related settings
chdir           = /home/zonghua/Documents/test_project
module          = test_project.wsgi:application
env             = DJANGO_SETTINGS_MODULE=test_project.settings_production
home            = /home/zonghua/Documents/test_project/venv
reload-mercy    = 10
user            = zonghua
uid             = zonghua
pcre-jit
thunder-lock
enable-threads
master          = True
threads         = 2
processes       = 4
socket          = 127.0.0.1:8001
chmod-socket    = 664
vacuum          = true

执行命令

uwsgi --ini uwsgi.ini 

运行情况

[uWSGI] getting INI configuration from /home/zonghua/Documents/test_project/uwsgi.ini
*** Starting uWSGI 2.0.12 (64bit) on [Tue Apr  5 13:59:02 2016] ***
compiled with version: 5.2.1 20151010 on 04 April 2016 01:12:07
os: Linux-4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016
nodename: x
machine: x86_64
clock source: unix
pcre jit enabled
detected number of CPU cores: 4
current working directory: /home/zonghua/Documents/test_project
detected binary path: /home/zonghua/Documents/test_project/venv/bin/uwsgi
chdir() to /home/zonghua/Documents/test_project
your processes number limit is 11829
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: enabled
uwsgi socket 0 bound to TCP address 127.0.0.1:8001 fd 3
Python version: 2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010]
Set PythonHome to /home/zonghua/Documents/test_project/venv
Python main interpreter initialized at 0x93b180
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415360 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x93b180 pid: 2781 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 2781)
spawned uWSGI worker 1 (pid: 2784, cores: 2)
spawned uWSGI worker 2 (pid: 2785, cores: 2)
spawned uWSGI worker 3 (pid: 2787, cores: 2)
spawned uWSGI worker 4 (pid: 2789, cores: 2)

uWSGI 文档

nginx 配置 文件 /etc/nginx/site-avaiable/test

server {
    listen 80;
    charset utf-8;
    client_max_body_size 75M;
    location /media {
        alias /path/to/project/media;
    }
    location /static {
       alias /path/to/project/static;
   }
    location / {
        uwsgi_pass 127.0.0.1:8001;
        include uwsgi_params;
    }
}

supervisor 配置文件 /etc/supervisor/supervisor.conf

使用 uwsgi

[program:test]
directory= /home/zonghua/Documents/test_project
command = /home/zonghua/Documents/test_project/venv/bin/uwsgi --ini /home/zonghua/Documents/test_project/uwsgi.ini
user = zonghua
autostart = true
autorestart = true
stopsignal = QUIT
redirect_stderr = true
loglevel = error
stdout_logfile = /home/zonghua/Documents/test_project/logs/uwsgi_out.log
stderr_logfile = /home/zonghua/Documents/test_project/logs/uwsgi_err.log
logfile_maxbytes = 1M

使用 gunicorn

1
2
3
4
5
6
7
8
9
10
11
directory= /home/py/www/thesis
command = gunicorn thesis_mis.wsgi --workers 6 --bind 0.0.0.0:8001 --env DJANGO_SETTINGS_MODULE=thesis_mis.settings_production
user = li
autostart = true
autorestart = true
stopsignal = QUIT
redirect_stderr = true
loglevel = error
stdout_logfile = /home/py/www/uwsgi_out.log
stderr_logfile = /home/py/www/uwsgi_err.log
logfile_maxbytes = 1M

查看状态

1
supervisorctl status all

启动

1
supervisorctl [start|stop|restart|status] test

Supervisor 文档