Running all tests in my current project takes some time. With 26 GB of free memory, why not use it for something useful? tmpfs is one way to speed up the test execution by keeping a complete file system in memory.
The problem with tmpfs is that it's only kept in memory. You have to setup the scripts yourself to flush content back to disk. These scripts should better work perfect, otherwise you'll loose parts of your work.
A common approach is to work directly in a tmpfs folder and backup your work to a folder on disk. When your machine is booting you restore the tmpfs folder from this backup folder. Once booted cron is used to synch the tmpfs folder and disk folder.
I found this setup a bit complicated and error prone. I never really trusted my own setup on boot time and with cron. Now I use a much simpler setup that is not using cron at all.
The performance on my machine running a single test, using the IDE and deploying in a web server was always reasonable. Just running all tests takes to much time.
The sweet spot I found is to setup a workspace on disk, sync to tmpfs under /dev/shm and run all tests there. This keeps my setup more or less unchanged and removes the possibility to loose work just because I'm too dump to setup things correctly.
The resulting performance increase is reasonable:
$ nosetests && run_tests.py ........................................................................................................................................................................................................................................................ ---------------------------------------------------------------------- Ran 248 tests in 107.070s OK ........................................................................................................................................................................................................................................................ ---------------------------------------------------------------------- Ran 248 tests in 19.423s OK
It's now five times faster than before.
With python the setup the setup is quite simple:
#!/bin/bash -e WORK=src/py LOG=$(pwd)/test.log TARGET=$(hg root) SHADOW=/dev/shm/shadow/$TARGET date > $LOG mkdir -p $SHADOW cd $SHADOW rsync --update --delete --exclude=".*" --exclude=ENV --archive $TARGET ./.. if [ ! -d ENV ] then virtualenv ENV fi . ENV/bin/activate cd $WORK python setup.py develop >> $LOG nosetests $* | tee -a $LOG exit ${PIPESTATUS[0]}
I'm just resyncing into a /dev/shm folder, setup the test environment there (virtualenv and python setup.py) and run the tests (nosetests).
It's is still possible to run single tests from the command line on the tmpfs folder. It's also possible to kick this off from your IDE but you'll loose your test runner and debugging capabilities. As I sad earlier I don't need these right now.
I hope my little twist with tmpfs helps with setting up a faster development environment without all the scripting hassle.
No comments:
Post a Comment