blog community

Welcome to blog community Sign in | Join | Help
in Search

Peter Hendriks

beans on the move

Using a RAM disk to speed up automated tests

A big benefit of automated testing is that it is (much) faster than testing by hand. This makes it possible to use testing as a form of instant feedback. Ideally, the test should be able to tell you something is broken immediately after it breaks. This means the basic test cycle should probably run not much longer as a few minutes. In fact, XP considers this a best practice (the 10 minute build).

When doing a lot of testing with files and databases on a large project, things start to slow down pretty soon. There are several ways to speed things up, like mocking slow dependencies that are not under test or using a fast in-process in-memory database like HSQLDB. HSQLDB is only suitable for very simple database test scenarios. A pragmatic alternative to speed up a real database is using a RAM disk!

A RAM disk emulates a disk drive by storing data in the RAM memory. This means its much faster as an ordinary hard drive, but all data will be lost when the machine shuts down. For an automated test, a RAM disk is a nice fast alternative to test IO and place a temporary test database. For Windows, a free RAM disk driver is available here, there are better commercial drivers available. Most other OS-es have RAM drive functions built-in.

The free driver enables a single drive up to 64mb, which is usually enough for automated testing and probably won't hurt overall system performance. Of course, an automated load- and/or performance test needs more data, but then you wouldn't want to do those kind of tests on a RAM drive anyway. :) When evaluating what to put on the RAM disk, also make sure that the database load scripts/contents are on it too, since this usually is read lots of times during the automated testing.

Published Sunday, March 18, 2007 8:40 PM by peterhe
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Jeroen Leenarts said:

I get the point of using a RAM disk. But to me it's just another point showing the baddness of  system like windows.

I've ran a few simple tests myself on OS X. Using a RAM disk makes no difference here. The reasoning behind this is simple. OS X recognizes which files are accessed a lot and memory maps those files. This works for writes and reads. Since OS X is a unix like system all I/O operations to disk are handled by the kernel and the kernel is free to decide when to actually write the memory buffers to disk.

Windows also has these sorts of optimizations, but apparantly "being smarter then your OS" still works with windows.

The memory mapping of files is just about the only reason why a proper shutdown is important, both with windows, OS X and any other modern desktop operating system.

Also I have seen someone perform these procedures on unit tests as well. Can't remember if it was Peter or not.

***

On another note, using ram disks can have a very significant benefit!! When running tests which change disk state, performing those changes on a RAM disk allows a very simple and speedy reset procedure. Just unload the ram disk from memory and reinitilize it, all data restored to a pristine condition.

March 18, 2007 11:45 PM
 

Peter Hendriks said:

Like any other optimization method, your mileage may vary. In a small test suite, the test bottleneck is typically not IO bound, and testing using ram disk usually needs some extra setup work, negating most of the performance benefits. I think you really only should start considering this when you are exceeding the ten minute build mark.

March 19, 2007 10:24 AM
 

frankb said:

Jeroen does have a point in that the OS should make sure that files that are frequently accessed should be cached in memory, in fact that is what every modern operating system (including Windows) does. The real bennefit a RAM drive will have is that it prevents all updates to Disk. Even when your OS uses delayed writes all changes will eventually get written to disk.

The same problem arrises with Databases, which usually guarantee Durability (aciD). This means that any committed transaction should allways be persisted to Disk. Even when you use a rollback transaction mechanism to reset the state of the database after the test, there will be IO involved to write the logfile etc. In this case I think A RAM drive could speed things up. I wouldn't call this beeing smarter than the OS, the OS (of DBMS) has no way of knowing that you are not interested in Durability.

March 19, 2007 12:20 PM
 

Jeroen Leenarts said:

Frank's remark is a good one.

Forced reads are circumvented by using a RAM disk. Might be a good reason to use RAM disks after all. :)

March 19, 2007 1:36 PM
 

Peter Hendriks said:

The reason why a ram disk is always faster is explained very well by Frank, and I assume even on an uber OS like the Mac OS X, using a ram disk can make a difference. ;) I did try this out for myself of course, and I did see significant performance gains. The reason I do not call any numbers is that it will probably vary dramatically, depending how much IO bound your test cycle is. In very small tests, the difference is probably none or worse, because using the ram disk reliably involves some extra setup. Resetting the ram disk does not seem more efficient to me than just deleting the files: deleting files should be even faster.

March 19, 2007 2:21 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

NL-JUG
Powered by Community Server, by Telligent Systems