Ruby Enterprise Edition - Mac OS X problem

Posted by marcin
on Saturday, July 26

Last weekend I decide to play a bit with Ruby Enterprise Edition to do some performance testing and especially memory footprint. The installation process of REE went as smooth as it could – personally I’m a big fun of the installers which guide user through the installation giving all the hints on the spot (well done guys!). After installation had finished I just couldn’t wait any longer to bind it with Phusion Passenger and see it in action. Also, as my mod_rails installation got a bit old (1.0.5) I decided to update it to the newest available version (currently 2.0.2). NOTE: if you upgrade from mod_rails 1.0.5 to 2.0.2 you need to change your Apache configuration file:

- RailsRuby directive is now called PassengerRuby

- RailsSpawnServer is now obsolete and you should use PassengerRoot instead.

I changed my httpd.conf file accordingly:

PREVIOUS CONFIGURATION FOR PASSENGER 1.0.5 AND REGULAR RUBY 1.8.6

#LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
#RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
#RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

NEW CONFIGURATION FOR PASSENGER 2.0.2 AND RUBY ENTERPRISE EDITION

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.0.2
PassengerRuby /private/opt/ruby-enterprise-1.8.6-20080709/bin/ruby

Note that PassengerRuby path leads to the Ruby Enterprise Edition installation folder.

After configuration change all you need to do is to restart your Apache, launch your application and benefit from lower memory footprint. In the end I was quite disappointed when I saw this error messages in Apache’s error_log file:

[Sat Jul 26 19:33:22 2008] [notice] Apache/2.2.6 (Unix) DAV/2 PHP/5.2.5 Phusion_Passenger/2.0.2 configured -- resuming normal operations
/Library/Ruby/Gems/1.8/gems/passenger-2.0.2/ext/passenger/native_support.bundle: [BUG] Bus Error
ruby 1.8.6 (2008-03-03) [i686-darwin9.2.2]

[Sat Jul 26 19:33:52 2008] [error] [client ::1] *** Unexpected error in Passenger: Cannot spawn application '/Users/xyz/Sites/my_rails_app': The spawn server has exited unexpectedly.

I’m not sure if this is problem specific to Mac OS X but noticed a few similar issues reported on the internet. Hoping that issue will be fixed very soon. Once it happens I’m going to give it another go and follow with some updates. Stay tuned!

Phusion Passenger a.k.a mod_rails

Posted by marcin
on Saturday, May 24

As deployment of even very simple web Rails apps was usually a pain (well, most of the cases) I decided to give mod_rails a go. The installation was a breeze as mod_rails installer guides you through the process nicely. Installation itself is as easy as that :

gem install passenger

Once your gem is installed run the following command (as root, otherwise you will get some “permission denied” errors)

passenger-install-apache2-module

Important note: In order to make Apache use your new shiny mod_rails you need to specifically modify its configuration by adding the following lines to your httpd.conf (NOTE: please change the paths accordingly!)

LoadModule passenger_module /Path/To/Gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
RailsSpawnServer /Path/To/Gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
RailsRuby /Path/To/bin/ruby

After that all you need to do to make your app working is to modify / create virtual host definition:

<VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /path/to/your/rails_app/public
</VirtualHost>

Now you are good to go ahead and restart your apache.

apachectl configtest
apachectl restart

For the test purposes I created a fresh rails app and start apache to serve it. The default page popped in on the screen which I took as a good sign ;) Next, I had created a simple controller with one action in it and then tried to reload the browser. The changes I made in the application weren’t reflected in the browser (the old version of the app was still in memory). Like in the case of standard setup (Webrick/Mongrel/etc.) with mod_rails you need to restart the application server in order for changes to take effect. One interesting thing here is that there is no command to be invoked from the command line to do it. Instead one need to create restart.txt file in application’s /tmp folder and then reload web browser pointing to your application.

touch /path/to/your/rails_app/tmp/restart.txt

Passenger loads your application into memory and keeps it there until one of the following events occur:

1. restart.txt has been created in application’s /tmp folder and web browser point to your app has been refreshed

2. Application has been idle for some time (the default it 120sec.) [see snippet below…]
[27:Application.h:264] Application 0x1a2ceb0: created.
[27:StandardApplicationPool.h:249] Cleaning idle app /path_to_your_app (PID 31918)
[27:Application.h:274] Application 0x1a2ceb0: destroyed.

If you have any issues with your deployment resulting in your app not being served / throwing errors go ahead and analyze your apache error_log (usually /var/log/apache2/error_log) and your application’s production log. It will give you some clues where things went wrong.

Also, mod_rails comes with pretty good documentation which can be found here.