python-3.x - Flask/uWSGI - 一段时间后进程过多

标签 python-3.x flask uwsgi

所有,我正在开发一个基于 Flask 的 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 屏幕截图(重新加载后几个小时):

htop output uwsgi/flask

一天后这会变得更长。当然,API 的响应速度会降低。 我该如何调试这个?有什么方法可以查看是什么让所有这些进程和子进程保持打开状态?请注意,API 并不是那么繁忙。我确实是目前唯一一个使用它的人,它很少有任何显着的负载,而且从来没有接近需要数十个进程的情况。

关于如何调试此流程膨胀问题有什么想法吗?

最佳答案

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

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

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

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

关于python-3.x - Flask/uWSGI - 一段时间后进程过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31063908/

相关文章:

python - MongoDB 聚合 - 按不同对分组

python - 如何禁用输入输入直到双击?

python - 调整条形图上的颜色编码,以便所有值在 matplotlib 中都正确编码

python - 如何将swaggerhub生成的flask swagger服务器部署到heroku?

python - 属性错误: 'Flask' object has no attribute 'login_manager' -- Login_Manager

python - 大型 Nginx/uwsgi 服务内容挂起 keepalive_timeout 秒

Python uwsgi w/virtualenv --no-site-packages -- import site = AttributeError {'userbase' }

python - 从 csv 中检索数据,并将 x 行和 y 列的值分配给变量。 Py3.2,*作业*

python - Flask-Session 扩展与默认 session

python - 在 Ubuntu 18.04 上安装 uwsgi 时出现问题