我使用 Python 3.7.3、uwsgi 2.0.18(docker 容器镜像 python:3-stretch)
我们有开发环境,我们在 flask 上运行代码,在生产中测试时将其更改为 uwsgi。我正在运行一个 py 脚本,该脚本从 redis(另一个容器)获取实时流 pcm 音频
现在,当我们在 flask 上运行它时,一切都正常!当我们在 uwsgi 上运行它时,线程会卡住并死亡。
uwsgi设置:
[uwsgi]
http = :5000
socket = :3031
wsgi-env-behaviour=holy
master=1
uid=1000
gid=2000
master=1
processes = 1
threads = 1
protocol = uwsgi
wsgi-file = server.py
chdir = /app/base/
callable = app
http-raw-body
single-interpreter
paste-logger = true
honour-stdin
#logto = /tmp/errlog
vacuum = true
harakiri-verbose = true
harakiri = 60
cpu-affinity =3
http-timeout = 60
optimize = 2
http-keepalive
listen=30
workers = 40
ugreen
reaper
start_response-nodelay
greenlet
日志:
HARAKIRI: -- wchan> 0
Wed Jun 5 15:55:48 2019 - HARAKIRI !!! worker 24 status !!!
Wed Jun 5 15:55:48 2019 - HARAKIRI [core 0] XX.XX.XX.XX- GET /pcm_json since 1559750087
Wed Jun 5 15:55:48 2019 - HARAKIRI !!! end of worker 24 status !!!
Wed Jun 5 15:55:48 2019 - *** HARAKIRI ON WORKER 27 (pid: 32, try: 1) ***
DAMN ! worker 10 (pid: 15) died, killed by signal 9 :( trying respawn ...
Respawned uWSGI worker 10 (new pid: 64)
关于 post 和 get 请求,flask 和 uwsgi 之间的主要区别是什么?
连续两天使用 googlins 后,无论我如何更改设置都没有任何帮助,我已经尝试了所有建议的方法。
我们正在考虑转向 gunicorn。谢谢。
编辑:
这是发送请求的代码:
conn = http.client.HTTPConnection(server, port)
headers = { "ID": ID, "debugLevel": 1, "Multipart": 1, "Audio": 1, "Accept": "application/json" } conn.request("GET", "/pcm", "", headers)
ret = conn.getresponse()
这是我在 cli 中看到的另一个错误
Unhandled exception in thread started by <function get_pcm>
答案1
因此,我弄清楚了是什么导致 uwsgi 工作者崩溃:
" harakiri = 60"
在我的 uwsgi.ini 配置中,因为我们的工作线程连接时间很长(提供直播),我猜 harakiri 认为它超载了或者花费了太多时间,所以 60 秒后它就会崩溃。
对于我们的服务器-多连接和直播,此设置有效:
[uwsgi]
http = :5000
socket = :3031
wsgi-env-behaviour=holy
master=1
uid=1000
gid=2000
master=1
threads = 4
protocol = uwsgi
wsgi-file = machine.py
chdir = /app
callable = app
http-raw-body
single-interpreter
paste-logger = true
honour-stdin
cpu-affinity =3
http-timeout = 60
optimize = 2
http-keepalive
listen=30
workers = 80
ugreen
reaper
start_response-nodelay
greenlet
offload-threads = 10