inicio sindicaci;ón

thefjord.org

The official online Fjord

Default GC Parameters for Ruby Enterprise Edition

Update: I’ve posted some more info on how to go about tuning the garbage collector in Ruby Garbage Collector Tuning: A Walkthrough

After attending Ruby Nation (which was awesome) and hearing a couple talks on how Ruby’s garbage collection works, I’ve been playing around some with the GC settings that REE lets you tweak. I’m still experimenting with the best setup, but I do know that by setting RUBY_HEAP_MIN_SLOTS to 600,000 (the default is 10,000), the Birdstack code base loads with 1 heap slot allocation instead of 7.

So, that’s an obvious win, and I wanted to make sure that all my app servers used that setting. Unfortunately, there’s no easy way to do that. My first thought was to look for a Passenger option to set the environment for the REE instances it launches, but that setting doesn’t exist, and that wouldn’t cover my delayed_job process or the cron jobs that run.

My solution was to write a wrapper around the ruby program itself. You can’t use a script as an interpreter for a shebang line (#!) with kernels earlier than 2.6.27.9, so for my deployment, it needed to be in C. It’s a pretty trivial program, but it gets the job done and ensures that all my Ruby programs use the correct GC settings.


GitHub Gist: http://gist.github.com/412737

Add whatever other GC settings you’d like and modify the exec line to point to your real Ruby executable. To compile, just do ‘make ruby’.

Read up on the other REE settings in the REE documentation. Give it a few reads; the way the allocator works isn’t totally obvious. I also recommend the Engine Yard blog post on the MRI allocator.

2 Comments »

Jesse McDonald wrote
June 5th, 2010 at 11:09 pm

You may want to try a variation on:

#!/bin/sh
exec ruby -x -S -- "$0" "$@"
echo "Failed to launch ruby interpreter." >&2
exit 1
#! marker to start real script: ruby
$stdout.puts "Ruby script!"

fjord wrote
June 6th, 2010 at 12:13 pm

And use that to replace my ruby binary? That won’t work on older kernels that don’t allow recursive shebang loading. That’s why my version was in C; my deploy environment is running 2.6.18.

Or did you mean that I should use that as a header on all my ruby scripts? I thought about that, but I really wanted a solution that would make these settings default for all of my scripts, so I wouldn’t ever forget to do those settings.

Or did I completely misunderstand what you were trying to do? :-)

Your comment

HTML-Tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>