Available for Hire!

ProgFu

programming tips & tricks

Sep 22

Make your Rails development faster with Ruby-perf and Zeus

Nothing is perfect and even a great framework like Ruby on Rails has its weak parts, and one of those is speed.

But I am not talking about speed in production where you can scale up to 50 instances in your cloud service and nobody really cares. I am talking about development speed. When your application starts growing and you start adding gems, it starts to take really long to start up, be it the server, console or just running a single spec.

Now in TDD/BDD, we try to combat this by either writing Rails-less specs which just use plain classes, or use something like spork. I’ve been happily using spork myself for quite some time, but there are things which spork just doesn’t do.

One of those is launching a console or starting a server. But there’s another gem that can do this for all of your Rails commands, and that is zeus. Zeus is smart, you don’t have to put it in your Gemfile or run it with Bundler, all you need to do is create a JSON config file via zeus init and then start the server zeus start.

After that, you’re ready to go, all you need to do is prefix every command with zeus. That means rails server becomes zeus server, rails console becomes zeus console, and so on.

There is one big advantage to this over spork, and that is you don’t need to add it to your project’s Gemfile and spec_helper. You just run it.

But this is not the end of the story. Zeus was designed to work with the new Ruby garbage collector. There is a patched version of Ruby which has backported the new GC from Ruby 2.0 dev, with some additional performance tweaks.

You can either install it via rvm

rvm reinstall 1.9.3-perf --patch falcon --force-autoconf -j 3

or rbenv

curl https://raw.github.com/gist/1688857/rbenv.sh | sh ; rbenv global 1.9.3-p194-perf

more detailed information can be found in this Gist.

From what I’ve tried, ruby-perf gives about 2 times better performance for running specs than 1.9.3, and almost 3 times better than 1.9.2. This of course might vary, depending on the project, but it will give you noticable boost in speed.

The gist also contains some more information about tweaking the GC HEAP, specifically

export RUBY_HEAP_MIN_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=1000000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=100000000
export RUBY_HEAP_FREE_MIN=500000

but you might not want to use this if you don’t have a lot of RAM.

For SCV Rush, the difference in running a single spec (thus Rails boot time) was going down to 4 seconds from almost 12 seconds, since I used 1.9.2 before.

I haven’t really had any issues with ruby-perf and zeus, so I can really recommend it for everyone to at least try it.


  1. limon7 reblogged this from progfu
  2. domstockdale reblogged this from progfu
  3. progfu posted this
Page 1 of 1