我最近切换到uWSGI用于我的Flask应用程序,事情一直进展顺利。我经常出现的一个奇怪的事情是,我会收到一堆警告:
[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
有什么想法吗?
注意:我无法增加进程或线程数,因为我每个线程都会加载一个非常大的数据结构,占用太多内存以便多次加载。
答案 0 :(得分:1)
你面临两个不同的问题。
uWSGI的固定缓冲区大小保护您免受那些“废话”请求的影响,因此这基本上是固定的。
完全异步队列的问题是由于您将堆栈设置为异步模式+ ugreen而产生的,我很怀疑您是否使用uwsgi async api重写了您的烧瓶应用程序。
请记住,要获得异步模式(包括gevent)的优势,您需要拥有100%非阻止应用,99.9999999%是不够的。
只是滥用uWSGI cow功能来共享大数据结构并增加进程数量。除非你为每个线程重新初始化你的数据结构,否则你绝对可以使用多个线程而不会改变你的应用程序(我甚至不确定它是一件容易的事情,因为uWSGI无法单独完成它)。