gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:31:22 34 4
gpt4 key购买 nike

所有,我正在开发一个基于 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com