1 Comment

Slow Ruby Install on Joyent

We are using Joyent to host a Ruby on Rails application. We noticed that our application seemed be running slower on our Joyent slice than our personal laptops. Out of curiosity we decided to run a simple benchmark test using irb on both our Joyent slice and our development machine. The following is the script that we ran.


require 'benchmark'; puts Benchmark.measure { 5000000.times {  1 + 1 } }

We were shocked to see a huge difference between our development machines, and our Joyent slice that was running ruby version ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-solaris2].

Development machine time:

1
2
>> require 'benchmark'; puts Benchmark.measure { 5000000.times {  1 + 1 } }
  1.070000   0.000000   1.070000 (  1.079934)

Joyent Slice time:

1
2
irb(main):001:0> require 'benchmark'; puts Benchmark.measure { 5000000.times {  1 + 1 } }
  2.070000   2.650000   4.720000 (  4.723583)

In order to correct the problem on our Joyent slice we compiled ruby 1.8.7 from source. After making this update we saw a huge improvement in the processing time.

Joyent Slice time after ruby update:

1
2
irb(main):001:0> require 'benchmark'; puts Benchmark.measure { 5000000.times {  1 + 1 } }
  0.890000   0.000000   0.890000 (  0.891699)

An incredible improvement! Really makes us wonder what kind of ruby install Joyent does out of the box.

The following walk through describes how we went about updating our Joyent slice. We found that this approach was much easier than trying to remove the old install of ruby.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Download, compile and install ruby 1.8.7 in /opt/ruby187
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz
tar zxf ruby-1.8.7.tar.gz
cd ruby-1.8.7
./configure --with-openssl-dir=/opt/local --with-readline-dir=/opt/local --with-iconv-dir=/opt/local --prefix=/opt/ruby187
make
sudo make install

# Download and install rubygems
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar zxf rubygems-1.3.1.tgz
cd rubygems-1.3.1
export GEM_HOME=/opt/ruby187/lib/gems
sudo /opt/ruby187/bin/ruby setup.rb

# Install gems needed to run the application
sudo /opt/ruby187/bin/gem install rake mongrel_cluster mysql

Edit .profile and put /opt/ruby187/bin at the beginning of the path.

This article on the Joyent wiki provided most of the steps we needed to take.