views:

843

answers:

4

My rails sites run Mongrel, I am having a problem with the amount of memory being used. My ruby-bin processes are using up about 66 MB of resident memory. How can I reduce the amount of memory used by rails?

It is not very economical to have many rails servers running on a single machine if they are eating memory at this rate. My php5 fcgi processes sit at between 15-25 MB.

I'm fairly unfamiliar with RoR, would using JRuby help? Any comments helpful in reducing memory footprint and increasing performance are more than welcome.

+7  A: 

You might look at Phusion Passenger and Ruby Enterprise Edition, which is the de facto standard setup for Rails apps these days. One of its aims is cutting memory use. It's also simpler than having a bunch of Mongrels.

Chuck
+1 I second the Passenger recommendation.
John Douthat
+1 I second the REE recommendation, as it include the MBARI patches making it consume much less memory. That or 1.9 also uses less. Also make sure you're running a 32 bit OS where possible.
rogerdpack
+3  A: 

If you are not tied to apache for something else, i would also try nginx with Phusion Passenger. If you're concerned about memory usage, you should see a smaller footprint from nginx than apache, and the lastest version of Passenger will download, compile and install nginx for you with minimal headaches.

PJ Davis
+1  A: 

I wouldn't go so far as to say Passenger is the de facto standard, but it's gaining a lot of traction. We just switched to Nginx+Passenger, and our ruby app (i.e. Mongrels vs. Passenger) memory footprint dropped from about 450MB to 295MB. It can drop less, as Passenger will kill off procs if they idle (this is configurable), but of course if you're getting traffic and it's using all of the instances you have it configured to, then they'll use up memory accordingly.

Note, that we are not using Ruby Enterprise Edition in our config yet (mainly because it's not yet available at Engine Yard), but we still are seeing a smaller memory footprint. Memory was the initial top reason we made the switch, but there are other benefits, such as faster and easier configuration for scaling up or down, and so on.

chrisrbailey
+3  A: 

You can also replace your mongrel process with Thin which is more efficient and has recently been patched in its Garbage Collection (thru eventmachine), to make it even better.

We use thin cluster behind nginx frontends with fine results.

Fer