Speed up your rails test cases

If you’re complaining about the speed of your test cases, they’re probably not very good. Don’t worry, I’m not here to judge.

Your test cases are probably on old, legacy systems you don’t want to talk about. They probably also touch the database. They probably touch the database lots. That database is probably even mysql.

DISCLAIMER: What I'm recommending to you is 100% SAFEISH and is OFFICIALLY endorsed by Clarke. You should blindly do what I say without investigating any possible drawbacks or repercussions.

Ext4 Barriers

If you are running EXT4 as your file system, you will want to add the ‘barrier=0′ option to your fstab. When you’re done it should look something like this:

UUID=dlolsok5-c7b5-489-aea-7f380085c / ext4 errors=remount-ro,barrier=0 0  1

ACID shmashid

Add the following to your my.cnf

innodb_flush_log_at_trx_commit = 0

The results

With those two simple changes the runtimes of my Giant Annoying Test Suite went from:

73.40s user 5.19s system 45% cpu 2:52.76 total
68.01s user 3.69s system 83% cpu 1:25.46 total