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

Philip Hallstrom mongrel at philip.pjkh.com
Thu Dec 21 21:52:18 EST 2006

> I've had a right fun few days at work trying to figure out why our Rails
> app (which isn't under very heavy load) kept eating memory and bringing
> our server to our knees. Eventually I traced it to send_file (which was
> in a way a relief as it wasn't down to my coding ;) -- every time a user
> started downloading, the memory consumed by the app would jump, and
> wouldn't go down again, even when they had cancelled the download (I
> haven't tested whether the memory would still be consumed after they
> completed the download). This has become apparent recently as the app
> has been used for larger files (150MB and upwards). As a fix I've
> delegated file serving to lighttpd + mod_sec_download, not quite as
> convenient but probably better in the long run anyway.
> So the problem is solved, but I was just wondering why this happened in
> the first place; according to the Rails docs, send_file buffers the
> response in order to not tie up memory. However, this was clearly not
> happening -- is this possibly related to how Mongrel interacts with
> Rails? If so, I gave it a try under lighttpd and still had the problem,
> any idea why? I'm really just looking to understand the issue better as
> I hate to walk away from a problem without fully comprehending it :)

You don't say it, but are you using the sendfile gem?  There was a lot of 
talk about there being serious problems with the sendfile gem on various 
platforms to the point that Zed explicitly told people to stop using 

Just a thought.

More information about the Mongrel-users mailing list