« Safari 3.0 / Webkit file upload problem with Rails 1.2 | Main | Guerrilla's Guide to Optimizing Rails Applications »

January 31, 2008

TrackBack

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

Listed below are links to weblogs that reference Garbage Collection is Why Ruby on Rails is Slow: Patches to Improve Performance 5x; Memory Profiling:

Comments

Erik Peterson

What version of Rails are you using?

I added the monkey patches in environment/initializers/optimizations.rb running Rails 2.0.2 and receive this error:

ArgumentError (wrong number of arguments (2 for 1)):
/vendor/rails/activerecord/lib/active_record/base.rb:2245:in `attributes_with_quotes'
/vendor/rails/activerecord/lib/active_record/base.rb:2245:in `update_without_lock'
/vendor/rails/activerecord/lib/active_record/locking/optimistic.rb:70:in `update_without_callbacks'
/vendor/rails/activerecord/lib/active_record/callbacks.rb:240:in `update_without_timestamps'
/vendor/rails/activerecord/lib/active_record/timestamp.rb:38:in `update'
/vendor/rails/activerecord/lib/active_record/base.rb:2238:in `create_or_update_without_callbacks'
/vendor/rails/activerecord/lib/active_record/callbacks.rb:213:in `create_or_update'

Gleb Arshinov

All the patches are against 1.2.4 That's what we use in production. For 2.0 try this ... Guess we should post 2.0 patches as well.
Updated: see 2.0 patches above.

Erik Peterson

I actually took a look at the source after posting my comment and arrived at changes identical to yours.

I've never poked around in the Rails source, but I can see this getting addictive. Especially since I'm deployed on a Solaris server running Ruby with dtrace probes.

Thanks for the posts, killer info.

Now I just need to get my app launched and stop optimizing prematurely. ;)

Gleb Arshinov

Eric: you could probably get all kinds of additional cool stats through dtrace. We've talked about it, but haven't had a chance to try it yet.

You are welcome. But, yuh, don't worry about optimizations just yet, launch it first :-)

Peter Harkins

Are you working to get any of these patches into Rails itself?

Gleb Arshinov

Peter: yes, we've started submitting patches to Rails and Ruby. E.g. see Rails ticket #10978. We should probably create a separate section with links on this page to track these submissions. End goal is to get all these or similar changes integrated upstream.

James

Pardon my ignorance... but how do you apply these patches?

Shanti Braford

This is great work. Thank you for posting this!

Michael Koziarski

Thanks again for the patches guys, keep them coming :)

Alan Miles

Thanks for helping me understand why. And it'd be good to see the patches accepted into Core.

For simple (i.e. no call-backs) but large data imports, I find the ar-extensions gem/plugin does the trick. By creating a single sql insert statement rather than looping through ActiveRecord::Base#create or #update thousands of times, the issues you've described are avoided. For me, it's created astonishing speed increases.

Dav Yaginuma

This looks like great stuff! Thanks for sharing.

Chu Yeow

Awesome awesome work Alexander (and all the other guys)!

Some of these patches have gone into core: the Benchmark#realtime one ( http://dev.rubyonrails.org/changeset/8771 ), and the attributes_with_quotes one ( http://dev.rubyonrails.org/changeset/8770 ) in particular.

Roger Pack

A patch to run the GC 'after each request' would be nice, too. Thanks for doing this stuff!

Roger Pack

To apply these you copy the code fragments into the bottom of 'config/environment.rb', or possibly other places, but that seems to work.

shabo

is this going to be included in official release ?

Al Brown

thanks for sharing this work. It will go along way towards closing ror's performance gap.

Roger Pack

It would be nice mentioning some quality asset manager plugins that can dramatically reduce total load time--like http://code.google.com/p/bundle-fu/ or http://synthesis.sbecker.net/pages/asset_packager

Gleb Arshinov

Shanti, Michael, Alan, Dav, Chu, Roger, Al -- you are welcome!

Alan, thanks for mentioning ar-extensions. Internally we've talked
about doing something like that, and it's great that it already
exists.

Yury Kotlyarov

Hi!

Just patched gc.c in ruby and freezed rails but rails run even slower at least on tests and specs. Any tricks here? Should I use ruby_prof to get performance boost? BTW I am on the Gentoo Linux box.

--Yury

Yury Kotlyarov

After increasing GC_MALLOC_LIMIT to 400M I can see better performance. So without any patching my tests completes in 20 seconds. With your patches in 21 seconds. After increasing GC_MALLOC_LIMIT - 18 seconds.

here is the patch:

Index: gc.c
===================================================================
--- gc.c (revision 15447)
+++ gc.c (working copy)
@@ -64,7 +64,7 @@
#if defined(MSDOS) || defined(__human68k__)
#define GC_MALLOC_LIMIT 200000
#else
-#define GC_MALLOC_LIMIT 8000000
+#define GC_MALLOC_LIMIT 400000000
#endif
#endif

Roger Pack

This post http://cfis.savagexi.com/articles/2007/07/18/making-rails-go-vroom by Charlie Savage shows some results that he got (and might be useful).

Lloyd Hilaiel

It would be interesting to see if there is any difference running your tests with a patched ruby:

http://lloydforge.org/projects/ruby/

There's an attempt there at adaptively performing GC rather than fixed at 8MB allocations. The goal being when you're in a period of intense allocation, to do less work trying to clean up.

Would be interesting to see how those low level techniques play out in a high level application...

fwiw,
lloyd

Gleb Arshinov

Lloyd -- looks interesting, we'll check it out.

Roger Pack

This looks like it has some potentially memory saving stuff, too.
http://pennysmalls.com [I'm serious].
-R

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