python - uwsgi 更便宜地杀死处理请求的 worker

标签 python flask uwsgi

我在 uwsgi 下有一个非常基本的 Flask 应用程序,由supervisorctl 下的信号管理。我使用更便宜的方法来扩展 worker ,并遇到了非常令人不安的情况。 uwsgi 正在杀死最旧的工作人员,即使它正在处理请求,导致 500。

如何防止uwsgi为了便宜而杀死处理请求的 worker ?

非常感谢任何帮助/提示。 发现另一个类似的帖子没有回复:UWSGI killing workers too fast

配置:uwsgi版本:2.0.4

# Auto-scaling
workers = 30
cheaper = 2
cheaper-step = 3
cheaper-algo = backlog
cheaper-overload = 2

日志:

[pid: 15601|app: 0|req: 13/78] 10.83.9.61 () {28 vars in 368 bytes} [Fri Sep 30 02:00:34 2016] POST /xxxxxxxxxxxx => generated 257 bytes in 151 msecs (HTTP/1.1 200) 2 headers in 72 bytes (1 switches on core 0)
[pid: 15601|app: 0|req: 14/79] 10.83.9.61 () {28 vars in 368 bytes} [Fri Sep 30 02:00:35 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 649 msecs (HTTP/1.1 200) 2 headers in 72 bytes (1 switches on core 0)
[pid: 15600|app: 0|req: 21/80] 10.83.9.62 () {28 vars in 369 bytes} [Fri Sep 30 03:30:08 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 2696 msecs (HTTP/1.1 200) 2 headers in 72 bytes (3 switches on core 0)
Respawned uWSGI worker 1 (new pid: 21009)
Respawned uWSGI worker 4 (new pid: 21010)
Respawned uWSGI worker 5 (new pid: 21011)
[pid: 15601|app: 0|req: 15/81] 10.83.9.62 () {28 vars in 370 bytes} [Fri Sep 30 03:30:09 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 3046 msecs (HTTP/1.1 200) 2 headers in 72 bytes (2 switches on core 0)
[pid: 15600|app: 0|req: 22/82] 10.83.9.63 () {28 vars in 370 bytes} [Fri Sep 30 03:30:10 2016] POST /xxxxxxxxxxxx => generated 0 bytes in 3347 msecs (HTTP/1.1 500) 2 headers in 127 bytes (7 switches on core 0)
worker 2 killed successfully (pid: 15600)       <------------- pid 15600 was interrupted, returned 500 (line above)
uWSGI worker 2 cheaped.
[pid: 15601|app: 0|req: 16/83] 10.83.9.62 () {28 vars in 369 bytes} [Fri Sep 30 03:30:12 2016] POST /xxxxxxxxxxxx => generated 0 bytes in 2560 msecs (HTTP/1.1 500) 2 headers in 127 bytes (3 switches on core 0)
[pid: 21010|app: 0|req: 19/84] 10.83.9.63 () {28 vars in 369 bytes} [Fri Sep 30 03:30:12 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 2931 msecs (HTTP/1.1 200) 2 headers in 72 bytes (4 switches on core 0)
worker 3 killed successfully (pid: 15601)       <------------- pid 15601 was interrupted, returned 500 (line above)
uWSGI worker 3 cheaped.
[pid: 21011|app: 0|req: 22/85] 10.83.9.61 () {28 vars in 370 bytes} [Fri Sep 30 03:30:12 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 3236 msecs (HTTP/1.1 200) 2 headers in 72 bytes (4 switches on core 0)
[pid: 21009|app: 0|req: 7/86] 10.83.9.61 () {28 vars in 370 bytes} [Fri Sep 30 03:30:12 2016] POST /xxxxxxxxxxxx => generated 0 bytes in 3532 msecs (HTTP/1.1 500) 2 headers in 127 bytes (4 switches on core 0)
worker 1 killed successfully (pid: 21009)       <------------- pid 15601 was interrupted, returned 500 (line above)
uWSGI worker 1 cheaped.
[pid: 21011|app: 0|req: 23/87] 10.83.9.63 () {28 vars in 369 bytes} [Fri Sep 30 03:30:15 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 1614 msecs (HTTP/1.1 200) 2 headers in 72 bytes (1 switches on core 0)
Respawned uWSGI worker 1 (new pid: 21013)
Respawned uWSGI worker 2 (new pid: 21014)
Respawned uWSGI worker 3 (new pid: 21015)
[pid: 21011|app: 0|req: 24/88] 10.83.9.61 () {28 vars in 369 bytes} [Fri Sep 30 03:30:17 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 2546 msecs (HTTP/1.1 200) 2 headers in 72 bytes (3 switches on core 0)
[pid: 21010|app: 0|req: 20/89] 10.83.9.62 () {28 vars in 370 bytes} [Fri Sep 30 03:30:15 2016] POST /xxxxxxxxxxxx => generated 0 bytes in 4845 msecs (HTTP/1.1 500) 2 headers in 127 bytes (6 switches on core 0)
worker 4 killed successfully (pid: 21010)       <------------- pid 15601 was interrupted, returned 500 (line above)
uWSGI worker 4 cheaped.
[pid: 21015|app: 0|req: 17/90] 10.83.9.61 () {28 vars in 369 bytes} [Fri Sep 30 03:30:18 2016] POST /xxxxxxxxxxxx => generated 186 bytes in 2402 msecs (HTTP/1.1 200) 2 headers in 72 bytes (3 switches on core 0)
worker 5 killed successfully (pid: 21011)       <------------- pid 15601 was interrupted, returned 500 (line above)

最佳答案

关于python - uwsgi 更便宜地杀死处理请求的 worker ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39801326/

相关文章:

python - Python 中的 GPGPU 编程

python - 将列表从大量字典转换为数据框的问题

python-3.x - 为什么 Google Chrome 会在我的 flask 网址中附加一个正斜杠,而实际上没有?

python - Flask 数据库可以在开发中使用,但不能在 uWSGI 的生产中使用

json - 如何使用 Flask 发送和接收大型 numpy 数组(几个 GB)

django - 未找到 uWSGI 命令

wsgi - uwsgi协议(protocol)和wsgi协议(protocol)有什么区别?

python - 使用 Cython 编译的外部 C 函数无法识别

python - 矢量图形中表面和形状的 3D 可视化

django - 使用 Django 同时运行 UWSGI 和 ASGI