Flask / uWSGI - 一段时间后过多的进程

时间:2015-06-26 02:29:25

标签: python-3.x flask uwsgi

所有,我正在使用uWSGI v2开发基于烧瓶的API作为应用服务器(如果相关,则使用NGINX)。 uWSGI .ini文件是:

[uwsgi]
module = WSGI
callable = app
master = true
processes = 5
socket = /var/uwsgi/api.sock
uid = gg_python
gid = www-data
vacuum = true
venv = /home/gg_python/flask_projects/api/apivenv3
die-on-term = true
daemonize = /tmp/uwsgi_daemonize.log

更新:这里是uWSGI启动摘要输出:

*** Starting uWSGI 2.0.10 (64bit) on [Fri Jun 26 08:31:52 2015] ***
compiled with version: 4.9.2 on 29 April 2015 17:23:06
os: Linux-3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24)
nodename: debian-api
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/gg_python/flask_projects
detected binary path: /home/gg_python/flask_projects/api/apivenv3/bin/uwsgi
your processes number limit is 7972
your memory page size is 4096 bytes
detected max file descriptor number: 65536
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/uwsgi/api.sock fd 3
Python version: 3.4.2 (default, Oct  8 2014, 10:47:48)  [GCC 4.9.1]
PEP 405 virtualenv detected: /home/gg_python/flask_projects/api/apivenv3
Set PythonHome to /home/gg_python/flask_projects/api/apivenv3
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x19faca0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 436608 bytes (426 KB) for 5 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x19faca0 pid: 20775 (default app)
*** uWSGI is running in multiple interpreter mode ***

过了一段时间(距离uWSGI的创业时间大约1天就足以看到效果),我得到了几十个开放流程。 htop screenshot(重新加载后几个小时):

htop output uwsgi/flask

一天后这会变得更长。当然,API的响应速度会降低。 我该怎么调试呢?有什么方法可以看到保持所有这些流程和子流程的开放性?请注意,API并不是那么繁忙。我现在真的是唯一一个使用它的人,它很少有任何重大负载,而且几乎没有任何需要接近几十个进程的东西。

有关如何调试此流程通胀问题的任何想法?

1 个答案:

答案 0 :(得分:3)

如果有人使用类似的设置看到此问题,则问题是禁用的线程。 uWSGI在启动时表明这一点(参见问题正文):

*** Python threads support is disabled. You can enable it with --enable-threads ***

添加命令行参数--enable-threads或将以下内容添加到uWSGU .ini初始化文件中:enable-threads=true

我确实在代码中使用了线程模块,一旦启用了线程,uWSGI就不会产生更多的进程。