Today I noticed that Ruby Enterprise Edition 2009.10 was released and I have really been wanting to see if I could get the SQL Server adapter tested and running under it. I am really curious how the speed improvements might look and will share my results below. This article assumes that you read my previous guide titled The Ultimate OS X Snow Leopard Stack For Rails Development - x86_64, MacPorts, Ruby 1.8/1.9, SQL Server, SQLite3, MySQL & More as I will be building on top of it and referencing certain steps. So let's get down to business.
The guys at Phusion have done a rock solid job. My previous attempts to install REE were a bomb, but it worked perfectly this time around. Simply follow their directions and all will be OK. A snippet of my output is below. I liked how they picked a new default install directory of
/opt/ruby-enterprise-1.8.7-2009.10. Wicked cool! By the way, the only issue I had during install was when they were trying to install the pg gem for me. I ignored that error for now.
$ sudo ./ruby-enterprise-1.8.7-2009.10/installer
Where would you like to install Ruby Enterprise Edition to?
(All Ruby Enterprise Edition files will be put inside that directory.)
Configuring For REE
This is actually really easy. In my previous article, I talked about installing MacPorts and configure your profile. All I did this time around was add the REE path extensions after my MacPort extensions in my ZSH kit. So my path file now looks this below. If I ever want to just go back to my normal 1.8/1.9 toggle in
/opt/local/bin, I just comment out the REE path extensions, source my profile and I'm back to my MacPort basics.
path=(/opt/local/bin /opt/local/sbin /opt/local/apache2/bin ~/.zshkit/bin $path)
In the last guide, I mentioned how to switch between ruby 1.8/1.9 installed by MacPorts using a simple ZSH function. You can find this in my article title MultiRuby The MacPorts Way. Testing Your Rails Apps With Ruby 1.9. I have updated this to include a condition that will noop the function if you are running REE. So to recap. I use my
chruby function to switch between 1.8/1.9 installed by MacPorts and I use my profile extension to use REE. So what that profile change done... reload and/or open a new terminal window and test it out.
$ which ruby
$ which gem
Using REE With SQL Server
Let's get the easy stuff out of the way and install the needed gems for the adapter to work. Again, always follow the TODO on the adapter page for the latest blessed versions of DBI and low level connectivity stuff. But just to recap the current needs.
$ sudo gem install dbi -v 0.4.1
$ sudo gem install dbd-odbc -v 0.2.4
$ sudo gem install activerecord-sqlserver-adapter
Now the hard part, but I have an easy solution. You can do this the hard way and recompile the UTF8 version of ruby odbc by hand or you can type one command. I tried compiling it by hand and found that I had a few bugs, even after following Jacob Riff's notes when he had a similar issue when trying to hook ruby ODBC to use unixODBC in his
/usr/local . My solution was much simpler. I just coped my ruby 1.8.7 ruby odbc to the REE's vendor ruby directory. Hence:
$ sudo cp /opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10/odbc.bundle /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/vendor_ruby/1.8/i686-darwin10.0.0
Here are my notes below on where I failed on installing ruby odbc by hand under REE. Feedback welcome, but good to know that the above simple copy worked just fine.
# Installing Ruby ODBC By Hand Notes
$ ruby -Cutf8 extconf.rb
$ make -C utf8
$ sudo make -C utf8 install
/usr/bin/install -c -m 0755 odbc_utf8.bundle /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/site_ruby/1.8/i686-darwin10.0.0
$ sudo mv /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/site_ruby/1.8/i686-darwin10.0.0/odbc_utf8.bundle /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/site_ruby/1.8/i686-darwin10.0.0/odbc.bundle
Loading development environment (Rails 2.3.4)
dlsym(0x102c6e330, Init_odbc): symbol not found - /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/site_ruby/1.8/i686-darwin10.0.0/odbc.bundle
Benchmarking REE vs MacPorts
Here is the good news, the above hacks and REE work! I have even tested the adapter and all is looking good from my end!!! Now how about those benchmarks? Here are the speed differences for running the full adapter test suite under 1.8.7 installed in MacPorts and the latest REE. Note, this is really non-scientific benchmarks, but I think they fun facts.
Ruby 1.8.7 MacPorts (patchlevel 174)
Finished in 158.574243 seconds.
2190 tests, 7395 assertions, 0 failures, 0 errors
REE 1.8.7 (2009.10)
Finished in 146.834762 seconds.
2190 tests, 7636 assertions, 0 failures, 0 errors
Since passenger was installed as part of the REE installation, all I had to do was run the apache2 installer again and paste in the new code into my httpd.conf file.
$ which passenger-install-apache2-module
$ sudo passenger-install-apache2-module