[Mongrel] Rails' send_file, Mongrel, and *gasp* memory

Zed A. Shaw zedshaw at zedshaw.com
Fri Dec 22 03:06:22 EST 2006


On Thu, 21 Dec 2006 19:09:33 -0800
"Jeremy Kemper" <jeremy at bitsweat.net> wrote:

> On 12/21/06, Ezra Zygmuntowicz <ezmobius at gmail.com> wrote:
> >
> >         The rails send_file method is not the same thing as setting an X-
> > SendFile header. If you are already using lighttpd for your server
> > then your in good shape. THe rails send_file method actually does
> > read the whole file into memory as it sends it to the client. SO you
> > will see memory problems like you have if you use it on large files.
> > The nice way to do it is to use the X-SendFile header in lighty. In a
> > rails action that just wants to serve a static file from somewhere
> > off the filesystem you can make it look like this:
> 
> 
> To be clear, send_file does not read the whole file into memory -- it blows
> chunks into the output stream. Mongrel and pure-Ruby FastCGI use StringIO to
> buffer the response before sending it to the client.
> 
> X-Sendfile is definitely the way to go in any case.

Just to be extra clear, neither of the two main systems for hosting Rails would need to buffer the output if Rails didn't alternate between sending headers and body content.

And yes, X-Sendfile is the way to go.

-- 
Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu
http://www.zedshaw.com/
http://www.awprofessional.com/title/0321483502 -- The Mongrel Book
http://mongrel.rubyforge.org/
http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.


More information about the Mongrel-users mailing list