【问题标题】:uWSGI seems to break when queries sent to it are too long当发送给它的查询太长时,uWSGI 似乎会中断
【发布时间】:2015-09-17 18:20:48
【问题描述】:

我最近为我的 Flask 应用程序切换到 uWSGI,并且大部分情况下进展顺利。经常出现的一个奇怪现象是我会收到一堆形式的警告:

[WARNING] unable to add HTTP_X_FORWARDED_PROTO=https to uwsgi packet, consider increasing buffer size
[WARNING] unable to add HTTP_X_FORWARDED_PORT=443 to uwsgi packet, consider increasing buffer size
[WARNING] unable to add HTTP_X_FORWARDED_PORT=443 to uwsgi packet, consider increasing buffer size
[WARNING] unable to add HTTP_X_FORWARDED_PORT=443 to uwsgi packet, consider increasing buffer size
[WARNING] unable to add HTTP_X_FORWARDED_PORT=443 to uwsgi packet, consider increasing buffer size
[WARNING] unable to add HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36 to uwsgi packet, consider increasing buffer size

并且遵循足够的这些,我会得到这些:

Tue Sep 15 16:57:48 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:49 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:50 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:51 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:52 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:53 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:54 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:55 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:56 2015 - [DANGER] async queue is full !!!
Tue Sep 15 16:57:57 2015 - [DANGER] async queue is full !!!

此时我的服务器会停止响应请求,直到它重新启动。

这往往会跟随某人向服务器发送一堆虚假的长废话查询,例如:

GET /autocomplete/5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555

我在 Nginx 后面运行 uWSGI。这是我的配置:

[uwsgi]
socket = 0.0.0.0:1234
protocol = http
wsgi-file = path/to/wsgi_server.py
callable = my_app
processes = 1
threads = 1
enable-threads = true
single-interpreter = true
async = 15
uGreen = true
logto = /path/to/my_log_file.log

有什么想法吗?

注意:我无法增加进程或线程的数量,因为我要为每个线程加载一个非常大的数据结构,这会占用太多内存而无法多次加载。

【问题讨论】:

    标签: python nginx flask uwsgi


    【解决方案1】:

    您面临两个不同的问题。

    uWSGI 的固定缓冲区大小保护你免受那些“废话”请求,所以这基本上是自己修复的。

    完整异步队列的问题是由于您将堆栈设置为异步模式 + ugreen,我很怀疑您使用 uwsgi 异步 api 重写了您的烧瓶应用程序。

    请记住,要利用异步模式(包括 gevent),您需要一个 100% 非阻塞应用程序,99.9999999% 是不够的。

    只是滥用 uWSGI 牛功能来共享该大数据结构并增加进程数量。除非您为每个线程重新初始化数据结构,否则您绝对可以在不更改应用程序的情况下使用多个线程(我什至不确定这是一件容易的事情,因为 uWSGI 无法自行完成)

    【讨论】:

    • 谢谢@roberto!您介意指出您指的是哪些 CoW 功能吗?我找不到太多关于它们如何工作或如何使用它们在工作人员之间共享数据的信息。
    猜你喜欢
    • 1970-01-01
    • 2013-05-01
    • 2015-11-08
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多