Python

燒瓶到 uwsgi 執行緒卡住

  • June 17, 2019

我使用 Python 3.7.3,uwsgi 2.0.18,(docker 容器鏡像 python:3-stretch)

我們有開發環境,我們在燒瓶上執行我們的程式碼,當我們在生產環境中測試它時,我們將其更改為 uwsgi。我正在執行一個 py 腳本,該腳本從 redis(另一個容器)獲取實時流 pcm 音頻

現在,當我們在燒瓶上執行它時一切正常!當我們在 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 之間的主要區別是什麼?

在連續 2 天使用 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>

所以,我想出了是什麼讓 uwsgi 工人崩潰:

" harakiri = 60" 

在我的 uwsgi.ini conf 中,因為我們的工作人員連接很長時間(提供直播),我猜 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

引用自:https://serverfault.com/questions/970252