Flask/uWSGI - 一段时间后进程过多
Flask/uWSGI - too many processes after some time
全部,我正在开发一个基于烧瓶的 API 使用 uWSGI v2) 作为应用程序服务器(w/ 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 屏幕截图(重新加载后几个小时):
一天后,这会变得更长。当然,API 变得不那么敏感了。
我该如何调试呢?有什么方法可以查看是什么让所有这些流程和子流程保持开放状态?请注意 API 并不是真的那么忙。目前我真的是唯一一个使用它的人,它很少有任何重大负载,而且从来没有需要数十个进程的情况。
关于如何调试此进程的任何想法 inflation 问题?
如果有人在类似设置中发现此问题,则问题出在线程被禁用。 uWSGI 在启动时指出这一点(见问题主体):
*** Python threads support is disabled. You can enable it with --enable-threads ***
添加命令行参数--enable-threads
或在uWSGU.ini初始化文件中添加以下内容:enable-threads=true
我确实在代码中使用了线程模块,一旦启用线程,uWSGI 就不会生成更多进程。
全部,我正在开发一个基于烧瓶的 API 使用 uWSGI v2) 作为应用程序服务器(w/ 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 屏幕截图(重新加载后几个小时):
一天后,这会变得更长。当然,API 变得不那么敏感了。 我该如何调试呢?有什么方法可以查看是什么让所有这些流程和子流程保持开放状态?请注意 API 并不是真的那么忙。目前我真的是唯一一个使用它的人,它很少有任何重大负载,而且从来没有需要数十个进程的情况。
关于如何调试此进程的任何想法 inflation 问题?
如果有人在类似设置中发现此问题,则问题出在线程被禁用。 uWSGI 在启动时指出这一点(见问题主体):
*** Python threads support is disabled. You can enable it with --enable-threads ***
添加命令行参数--enable-threads
或在uWSGU.ini初始化文件中添加以下内容:enable-threads=true
我确实在代码中使用了线程模块,一旦启用线程,uWSGI 就不会生成更多进程。