« Garbage Collection is Why Ruby on Rails is Slow: Patches to Improve Performance 5x; Memory Profiling | Main | Make Your Ruby/Rails App Fast: Performance And Memory Profiling Using ruby-prof and KCachegrind »

January 31, 2008

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451c8d369e200e5501bb4a18834

Listed below are links to weblogs that reference Guerrilla's Guide to Optimizing Rails Applications:

Comments

Carl Youngblood

Have these patches been submitted to the Rails core?

Carl Youngblood

Never mind. Looked at the previous post and got my answer.

Alistair Holt

I really love seeing people optimising the Rails core like this. Fantastic.

khelll

i have been trying the new ruby-prof ver 0.6.0
but i could't c the memroy profiling in the log
i followed ur instructions in patching ruby gc and using the line RubyProf.measure_mode = RubyProf::MEMORY

but still unable to run memory profiling in my rails app :(
can u explain more how to do so?

Shanti Braford

I'm guessing ruby can be patched to raise the memory limit at which point its GC gets called?

Great stuff though -- looking forward to seeing some of this in Rails core.

Morgan

Greetings,
It's great stuff, and certainly valuable, but GC pauses should never impact the user, since I believe you should be handling all page requests with the GC disabled, and only enable (and start) GC after you've disconnected from the user.

I believe FastCGI, for instance, does it this way.

It's definitely nice to get rid of unnecessary allocations, but if you're running Rails with GC disabled during the page request, I believe these suggestions probably won't net you much user-visible speedup.

I'd *love* to hear differently mind you, as I do, in fact, work on a large consumer Rails app. :)

-- Morgan

Alexander Dymo

Usual deployment scheme for rails app is running several mongrels on one or more machines. In this case you can't disable GC. One of the lengthy requests processed in one mongrel can take too much memory and other mongrels will be swapping all the time. So the overall performance will go down. And like I described in the blog post, it's not that uncommon for rails process running in mongrel to take 1 Gig of RAM ;)

Things only get worse if you run on memory-restricted hosting, say VPS with 512M of memory. You basically need GC there.

What you can certainly do is to increase the memory threshold for ruby GC from 8M to 16M or 32M (read http://whytheluckystiff.net/articles/theFullyUpturnedBin.html for more insight). Thus you'll have fewer GC collections but each of them will take a bit longer time. Still, you'll need to manually fine-tune the setting to get the good performance.

Tim Case

Hi, thanks for this great write up on ruby-prof. I'm following along and have rebuilt ruby with the patch included above. After changing my path and verifying that I'm using the patched version of ruby, I've found that this patched version of ruby can't find my installation of ruby gems:


irb(main):001:0> require 'rubygems'
LoadError: no such file to load -- rubygems
from (irb):1:in `require'
from (irb):1
irb(main):002:0>


Did you run into this issue?

Alexander Dymo

Please check that you've installed the new ruby into the same location as the old one. In case you installed it into the new location, you'd need to install rubygems package and all your gems again.

Tim Case

Thanks! That worked! I also found that if I symlinked gems from my new location's bin, it would also work with the new location. Thanks again.

Tim Case

Correction: My little symlink trick didn't actually work, but the solution you described above did.

Mathieu Martin

Excellent stuff guys!

@Alex and @Tim:

I've got a patched Ruby in my /usr/local. (thanks to http://hivelogic.com/articles/2008/02/ruby-rails-leopard )

I also ran into the problem outlined by Alex. However I'm not sure I understand the fix of installing the new ruby "in the same location". I'm not too willing to actually overwrite my unpatched Ruby and I guess it's not what you mean ;-)

However just copying the (suspiciously small) /usr/local/bin/ruby executable under another name doesn't work either... I guess it's just a small executable that hardcodes the 'prefix' dir from the Makefile and therefore still loads everything from /usr/local/lib.

So could you explain in a little more details how to unobtrusively install this second version of ruby?

Meanwhile I'm going to try the lazy approach. I will install the same rubygems version as on my normal Ruby install, then make a backup of /usr/local/lib/ruby/gems and copy my current gems directory in its place.

I'll report on whether that works :-)

anon

Is this article still valid with Rails 2.1.0 ?

Dave L

Hey, just wondering if these updates still apply to the current rails 2.1 version or 2.2 even?

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Buzzletter

  • Hear about our new Ruby on Rails performance improvements, hacks, recipes, plugins & more. Enter your email below