On 08.06.2012 18:15, André Cruz wrote:
Hello.
I'm running a Django app served by uWSGI standalone. One of the views needs to
send a file as a response, after doing some DB lookups. What is the most
efficient way to send a static file to the client in this situation? I can't
offload this to another server (X-Sendfile or X-Accel) since there isn't one.
Should I use wsgi.file_wrapper? There is a patch
(https://code.djangoproject.com/ticket/2131) under review which aims to add
this feature.
Another question that I have is that, since I'm using the GEvent loop, will the
worker be busy while sending the file to the client therefore starving the
greenlets of that worker? I ask this because the Gevent monkey patching that I
rely on will not affect the socket calls done by uwsgi while serving the file,
therefore they may block.
Wild guess (based only on googling) about a most efficient way to send a
static file: uwsgi.sendfile (shortcut to kernel sendfile). I.e.:
import uwsgi
uwsgi.sendfile(filepath) # or uwsgi.sendfile(fd)
Citing [1]: "Look at the uwsgi.sendfile() function. This is the fastest
way to send file data to you clients." Citing [2]: "The sendfile()'s
uWSGI (where available) implementation is async-friendly, so if you need
to serve a lot of static files wrapped by python, async mode is a good
choice. Look at the tests/fileserve_async.py file for an example use."
[1] http://projects.unbit.it/uwsgi/wiki/CustomRouting
[2] http://projects.unbit.it/uwsgi/wiki/AsyncSupport
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi