Some uwsgi settings for Django with StreamingHttpResponse
By Vince
I have been working with Django quite a bit the last few months, and finally deployed the app into production. The setup uses uwsgi and nginx.
My Django app uses threads quite a bit, and when deployed to development server using uwsgi/nginx, it was painfully slow. As in it took 15 minute to run commands that should take 30 seconds. So it took a while of experimenting, and determined that a setting was missing in the uwsgi configuration.
enable-threads = true
Simple enough right? Just need to enable thread support if you are using the threading module for python.
The second item I had issues with was streaminghttpresponse in Django. This lets you iterate data over time to an open http session. This is great for networking since we are running commands that take awhile to finish, and we can give status updates as it is running.
The behavior worked with the built in Django web server, but using uwsgi/nginx it didn’t stream at all. It would sit there and wait for the thread to finish and then it displayed on the page.
http-auto-chunked = true
add-header = X-Accel-Buffering: no
These commands enable the chunked options for http transport protocols, and adds an http response header that tells nginx to send data as it is streaming (X-Accell-Buffering).
So with these three configuration settings in the uwsgi INI file, everything works great.
Hope this helps someone on their Python, Django, uwsgi, nginx journey!