Dec 22, 2010

Speeding up Slow Specs and Features on Ubuntu 10 with Postgres

I’ve recently been working on a Rails 2.3.10 project using Ubuntu 10 and Postgres 8.3 on my dev machine. The specs and features were running really slow (>30min) and I wanted to speed them up.

After some profiling and searching I found 2 quick fixes.

1. Tell postgres not to wait for confirmation that changes are committed to disk:

Add the following lines to your postgres configuration (/etc/postgresql/8.3/main/postgresql.conf) and then restart postgres. These have a very noticable affect on Ubuntu 10 using the ext4 filesystem. They tell postgres not to wait for confirmation from the filesystem that changes have been committed to disk, which results in table truncates/deletes being faster but also increases the chance of a corrupt db if your machine crashes. (that shouldn’t matter for dev/test)

  fsync = off
  synchronous_commit = off

2 – Use Ruby Enterprise Edition

If you haven’t seen the ‘Grease your Suite’ presention – you should watch it. If you are using rvm and can use REE on your project, you should do so. It is a lot faster (for my tests at least). It reduced my test time by 40%.

If you do use REE – add the following to your ~/.bashrc file

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

These exports optimize memory allocation and garbage collection for REE.

After these 2 changes the entire test suite took 9min. That is still pretty long, but much better than >30min.