Older posts...
Older posts...
28 Sep
How I'm going to land my dream job
28 Sep 2014
How I'm going to land my dream job
1 Oct
Neural net training fail
1 Oct 2014
Neural net training fail
13 Oct
Pow + SSL without the hassle
13 Oct 2014
Pow + SSL without the hassle
17 Oct
Using machine learning to rank search results (part 1)
17 Oct 2014
Using machine learning to rank search results (part 1)
23 Oct
Using machine learning to rank search results (part 2)
23 Oct 2014
Using machine learning to rank search results (part 2)
9 Nov
Managing complexity in Go
9 Nov 2014
Managing complexity in Go
25 Nov
Remote work: an engineering leader's perspective
25 Nov 2014
Remote work: an engineering leader's perspective
19 Sep
Running A/B tests on our hosting infrastructure
19 Sep 2016
Running A/B tests on our hosting infrastructure
19 Jan
Optimising Redis storage, part two
19 Jan 2017
Optimising Redis storage, part two
27 Mar
Every service is an island
27 Mar 2017
Every service is an island

mrd - MySQL in a RAMDisk for speedier tests

We try to live by the “red, green, refactor” mantra at HouseTrip. As a consequence we have good test coverage, but our test suite is getting larger. This is just one of the tricks that help us run our tests faster.

This was reposted from HouseTrip’s developer blog.

Many of our tests tend to use live ActiveRecord objects, which means the database can be a speed bottleneck. Even with good SSDs, the heavy, synchronous I/O performed when creating and modifying records is a grind.

A common idea is to make your test database’s storage live in memory instead of on-disk, and that’s exactly what mrd sets up for you.

Yes, mrd is pronounced like the french swear word, (sorry if you find that in poor taste). The rationale here, is that you might end up saying that word a lot (or the equivalent in your own language) after manually setting up MySQL-in-a-RAMdisk a couple of times.

Fortunately, setting up mrd is trivial; just install like so:

$ gem install mrd
Successfully installed mrd-0.0.3
1 gem installed

and run:

$ mrd
==>
Created Ramdisk at /dev/disk4
Formatted Ramdisk at /dev/disk4
Mounted Ramdisk at /Volumes/MySQLRAMDisk
Starting MySQL server
MySQL is now running.
Configure you client to use the root user, no password, and the socket at '/Volumes/MySQLRAMDisk/mysql.sock'.
Just close this terminal or press ^C when you no longer need it.

Then, if using Rails, point your database.yml to this new temporary SQL server:

test:
  ...
  socket: /Volumes/MySQLRAMDisk/mysql.sock

Don’t forget to setup your test database:

$ bundle exec rake db:create:all db:test:prepare

Voila! Slightly faster tests.

A couple of caveats to finish:

  • mrd only supports MacOS, but you’re very welcome to fork & extend for other platforms!
  • This is a hastily hacked together script. I’ve been using it for six months without problems though.