Speeding up SQLite based unit tests


If you write database driven applications, you probably have used SQLite at some point. Since it is a simple embedded database, it is a logical choice to use for unit tests that go to the database. However, SQLite performance on Ext4 (default Fedora File system) is lack-luster.
A cheap way to speed things up is to use a ramdisk as the backing store for the database.

Openstack Keystone runs unit tests against a database stored in the keystone/tests directory. A typical unit test run gives times like this:

Ran 455 tests in 369.486s

Six minute test runs really mess with your flow.

The easiest way to speed things up is to make this into a ramdisk.

— UPDATE database is now in tests/tmp–

sudo mount -t tmpfs -o size=256M tmpfs /opt/stack/keystone/tests/tmp
# this line is not needed -->  sudo chown $USER /opt/stack/keystone/tests
cd  /opt/stack/keystone/
git checkout HEAD tests/tmp

That produces

Ran 456 tests in 27.262s

Yes, I will take a factor 12 speed up, thank you very much.

3 thoughts on “Speeding up SQLite based unit tests

  1. Had a conversation with a coworker that suggested the same thing. The reason I went this route is that it did not involve changing the unit test or checked out code at all, which is sometimes what you want.

  2. I was doing something very similar to this when I was migrating an SVN repository. I ended up using /dev/shm as my ram disk because it’s already setup on any modern Fedora box. That way you don’t have to manage/setup/destroy your RAM disk when you’re done.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.