当你的系统存在一些IO或网络请求较久的操作时, 如果以默认的方式启动uwsgi服务,
那么如果这类请求过多的时候, 所以进程被卡死. uwsgi就无法再对后续请求做处理了.
这时可以用gevent的方式跑起uwsgi服务, 这样当某个请求在IO或网络请求中时, uwsgi进程可以去处理其他的请求.
如果环境没装gevent的话需要先安装gevent:
pip install gevent
启动方式:
uwsgi --gevent 100 --gevent-early-monkey-patch uwsgi.ini
顺便把uwsgi文件的配置也放出来下:
[uwsgi]
base = path
chdir = path
wsgi-file = manage.py
callable = app
pidfile = project_pid
master = true
processes = 4
socket = 0.0.0.0:8080
# http = 0.0.0.0:8080
vacuum = true
buffer-size = 32768
listen = 1024
# log-reopen = true
# daemonize = %(base)/logs/project.log
supervisor配置如下:
[program:project]
process_name=%(program_name)s
command=/home/ubuntu/.virtualenvs/project/bin/uwsgi --gevent 100 --gevent-early-monkey-patch /var/www/prod/project/uwsgi.ini
autostart=true
autorestart=true
stopsignal=QUIT
user=root
numprocs=1
redirect_stderr = true
stdout_logfile=/var/log/python/project.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=5