Reputation: 39009
I recently switched over to uWSGI for my Flask app, and things have been going well for the most part. One oddness that has been coming up every so often is I'll get a bunch of warnings of the form:
[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
And following enough of those, I'll get these:
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 !!!
At which point my server just stops responding to requests until it gets a restart.
This tends to follow someone sending a bunch of spuriously long bullshit queries to the server, like:
GET /autocomplete/5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
I'm running uWSGI behind Nginx. Here's my config:
[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
Any ideas?
Note: I can't increase # of processes or threads because I'm loading a very large data structure per thread that takes up too much memory to be loaded multiple times.
Upvotes: 1
Views: 3877
Reputation: 12953
You are facing two different problems.
The fixed buffer size of uWSGI protected you from those "bullshit" requests, so this is basically fixed by itself.
The problem of full async queues is generated by the fact that you set your stack in async mode + ugreen, and i am pretty doubtful you rewrote your flask app using the uwsgi async api.
Remember, to get advantage of async modes (included gevent) you need to have a 100% non blocking app, 99.9999999% is not enough.
Just abuse uWSGI cow features to share that big data structure and increase the number of processes. You can absolutely use multiple threads without changing your app unless you re-initialize your data structure for each thread (and i am not even sure it is an easy thing to do as uWSGI has no way to do it by itself)
Upvotes: 1