When Ruby goes wrong

Cool/funny/stupid stuff, Ruby on Rails, Technology 3 Comments »

Running the tests, 1 failure. Doesn’t look like a failure to me :)

Investigating…


1) Failure:
test_new_articles(AnnounceArticleFunctionalTest)
[test/functional/announce_article_test.rb:74:in `test_new_articles'
/usr/lib/ruby/gems/1.8/gems/mocha-0.5.6/lib/mocha/test_case_adapter.rb:19:in `__send__'
/usr/lib/ruby/gems/1.8/gems/mocha-0.5.6/lib/mocha/test_case_adapter.rb:19:in `run']:
<Wed, 21 May 2008 15:12:50 +0000> expected but was
<Wed, 21 May 2008 15:12:50 +0000>.

How to fix that Rubygems mess on Leopard

Ruby on Rails, Software development 27 Comments »

I love Leopard and I love my Mac. I think Apple made the right decision by bundling Ruby and Rails with Leopard. However, I believe they screwed up big time in the execution.

Leopard’s Rails installation worked great until I updated Rubygems with sudo gem update –system. After I did that, most of my gems were broken, and reinstalling them didn’t help. According to Google, I was not alone.

The right thing to do for Apple would have been to ship Leopard with MacPorts and have Ruby and Rubygems installed through it. Unfortunately, they had to reinvent the wheel…

This tutorial will guide you through fixing that mess. We will be reinstalling Ruby and Rails with MacPorts and deleting the original Ruby installation to avoid conflicts.

You might want to backup your system before proceeding as I cannot be held responsible if something goes wrong (my lawyer made me write that). I tried it on 2 different machines and it worked fine for me.

So let’s get started already!

Step 1: Install MacPorts

Start by installing MacPorts if you don’t already have it on your machine. It’s an awesome must-have piece of software anyways! It’s super easy to install with the Leopard package.

Step 2: Install XCode 3.0

You must also have XCode 3.0 installed. It’s a huge download so you might want to install it from your Leopard DVD. It’s in /Optional Installs/Xcode Tools/XcodeTools.mpkg

Installation will take some time, so go read Digg, Reddit, or install Defensio on your blog!

Step 3: List your gems

Get a list of your installed gems and save it to a text file somewhere. You will need to reinstall them!

Step 4: Clean up your Mac

In order to avoid conflicts with your original Ruby installation, I recommend you simply delete it. To do so, run these commands (I know… scary stuff!):

Step 5: Install Ruby and Rubygems with MacPorts

If you don’t perform step 4, you will run into problems at step 6.

Now go ahead and install Rubygems through MacPorts. It will automatically install Ruby (and many other things) as it’s a dependency. The command is:

This one will also take a while… When it’s done, update Rubygems:

Step 6: Install Rails

At this point, you should have a brand new Ruby and Rubygems installation working! That wasn’t too hard was it?

Now let’s install Rails.

  • For Rails 1.2.6, run
  • For Rails 2 (aka latest-and-greatest), run

Note that recent versions of Rubygems no longer requires the –include-dependencies parameter.

Step 7: Reinstall your gems

Now’s the time to reinstall your original gems.

To reinstall the gems that shipped with Leopard, execute this command:

Then, you might want to reinstall the other gems you had. The list is on your desktop in installed_gems.txt.

That’s it! You now have a more standard and less prone to problems Rails stack on your Mac!

A better approach to restarting a Mongrel cluster

Ruby on Rails 2 Comments »

At Karabunga, we use Mongrel, a lot. As our Rails applications become larger, the startup time of a Mongrel process becomes significant.

As you know, restarting your a Mongrel cluster is a matter of issuing this command: /etc/init.d/mongrel_cluster restart. Here’s what happens for a cluster of 4 Mongrels:

A typical Mongrel Cluster restart

For one of our application, the “stop” time is about 2 seconds and the “start” time is somewhere around 10 seconds for each Mongrel process. Which means that for a cluster of 15, we have a window of about 3 minutes where at least 1 and often many Mongrels are innaccessible. Worse, there’s even a point where there is no Mongrel running at all. In a high traffic production environment, this is not acceptable.

With some hacking, I managed to modify mongrel_cluster_ctl (the script called by /etc/init.d/mongrel_cluster) to avoid the above scenario. My hack also makes sure that at most 1 Mongrel will be down at any given time. Here’s a graphical representation of my hack:

A Mongrel Cluster restart with my hack

I believe this is much more efficient. Moreover, when implemented with Swiftiply, downtime is reduced to zero since Swiftiply will detect a “dead” Mongrel and route requests to one that is alive.

Links:

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in