Wednesday, March 18, 2009

Sending files from ruby without blocking

Sometimes you need to provide some processing before sending large files. i.e To verify the user is logged in or has paid for the resource.

The problem with sending large files from Rails, is that the process can block until the file has completed. This knocks out one of your processes that could be dealing with requests.

Fortunately you can use X-Sendfile, which offloads the work to apache to handle and your process will continue working. You just say what file you want to send and it returns. There's an apache module that does all the hard work.

Here's a more thorough explanation.

No comments: