In the Tail

Exploring the niche consumer

Ruby Enterprise Edition

October 8th, 2008

As I’ve added more web sites to my Slicehost VPS the amount of memory required to run each Rails instance started being a real factor. I started looking for a solution for the memory footprint, the first thing I tried was upgrading to 1.8.7 and while it was faster than 1.8.6 it also broke some stuff like Mephisto and did not reduce the memory footprint.

Then I found out about Ruby Enterprise Edition they claim it reduces memory consumption by 30%. It's setup to be installed in a different directory than the standard Ruby to not interfere with other production apps, so I gave it a try. Mine was installed in the /opt/ruby-enterprise-1.8.6-20080810/ directory which I linked to /opt/ruby-enterprise. The installation was easy and painless, the only thing you have to remember is that you'll have a new sparsely populated GEM directory, so you might want to go ahead and /opt/ruby-enterprise/bin/gem install <insert your favorite gems here>

I was using Apache (I know should be using nginx, but then I couldnt use mod_rails) and Mongrel to serve my Rails instances, but to really benefit from Enterprise Edition, I needed to switch to Phusion Passenger (aka mod_rails). This too was very easy, the only trouble I had was I had to tell the installer where my Apache 2 header files were export APXS2=/opt/apache2/bin/apxs did the trick.

Then you need to add the passenger_module from your Apache httpd.conf file with:
LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /opt/ruby-enterprise/bin/ruby

Almost done, I just had to take the bits about routing to the mongrel cluster out and I was running my Rails instances with mod_rails

For my Merb app I had to add a config.ru file in the root directory with the following information

1
2
3
4
5
6
7
8
9
10
Gem.path.unshift("/opt/ruby-enterprise/lib/ruby/gems/1.8")
require 'rubygems'
Gem.clear_paths 
require 'merb-core' 
 
Merb::Config.setup(:merb_root   => ".", 
                   :environment => ENV['RACK_ENV']) 
Merb.environment = Merb::Config[:environment] 
Merb.root = Merb::Config[:merb_root] 
Merb::BootLoader.run 

Notice the bit about adding the correct GEM path for Ruby Enterprise Edition then clearing it out after loading rubygems, I'm not exactly sure why that is required, but it took me a while to figure it out

So that's it now I have multiple Rails apps and one Merb app running on a Slicehost VPS using mod_rails. To be honest though I have not seen a big reduction in memory but the configuration is much easier.

Leave a Reply