Ruby on Rails and Memory Usage / Leaks

June 18, 2008

I’ve been running ClockingIT for quite a while now, and at some point something was introduced which made the memory usage grow and grow over time. I installed God to monitor and restart my Mongrels whenever they grew too big, but I can’t say I’ve been very comfortable with that solution.

Then, when I bought a new server to run on, I figured I’d get a bit more RAM and go 64bit to be able to use it. And found out that Ruby uses ~ 2x the memory, due to addresses in every object taking double the space.

I took some time to look for a better solution, and found something which works really great for me.

Enter Thin, Slim Attributes, Erubis and a Ruby GC patch:

Setup                        Time   VIRT    RES
-----------------------------------------------
MRI/Mongrel             0m37.607s 181660 120720
MRI/Mongrel/Erubis      0m37.536s 181660 120920
MRI/Mongrel/Slim        0m36.399s 181672 119300
MRI/Mongrel/Erubis/Slim 0m36.020s 182696 120064

GC/Mongrel              0m37.416s 177560 119268
GC/Mongrel/Erubis       0m37.260s 172440 114484
GC/Mongrel/Slim         0m35.024s 164260 105656
GC/Mongrel/Erubis/Slim  0m35.049s 163236 104656

MRI/Thin                0m36.828s 172624 111512
MRI/Thin/Erubis         0m36.878s 175696 114724
MRI/Thin/Slim           0m35.457s 175708 113532
MRI/Thin/Erubis/Slim    0m35.087s 176732 114700

GC/Thin                 0m36.208s 166476 108888
GC/Thin/Erubis          0m36.121s 166476 108724
GC/Thin/Slim            0m33.854s 155224  97060
GC/Thin/Erubis/Slim     0m33.832s 155224  97080

Keep in mind that this is on a 64bit platform, so a 32bit version would use ~ half the memory.

I’m getting a lot fewer restarts of my webservers with this setup, which can only be a good thing. It’s also been rock solid after ironing out a couple of problems with Slim Attributes.

Advertisements

2 Responses to “Ruby on Rails and Memory Usage / Leaks”

  1. roger Says:

    You could also try Ruby Enterprise Edition. It runs normal servers [like thin] but faster. I guess if you used mod_rails you might be able to save, too.

    What problems with thin attributes were there? Does the author know?
    Thanks!
    -=R


  2. The author was notified, and had released a fix the day after, so it works perfectly now.

    I’ve yet to try the Ruby Enterprise Edition, and I don’t really want to run Passenger (mod_rails) as my Apache isn’t quite as lean as it ought to be.

    — Erlend


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: