Just a Few Lines

That's all it takes, usually...

RAM disks for fun and profit

October 16th, 2009 |

Some time ago I was digging through my very old files, back from Windows 9x days. One of the interesting things was a note I wrote to myself, explaining how to setup a RAM disk. While glancing through it an idea struck me – “can I use it for Tomcat and other Java stuff?”.

It turns out, I can. If you don’t feel like reading the whole story, here’s the bottom line: use RAM disk for everything Java – it’s WAY faster than HDD. For more details, read on.

What is a RAM disk?

Wikipedia explains it quite well. Simply put, it’s a block of RAM memory that operating system treats as a regular hard drive. Two main differences between a RAM disk and hard disk are speed (RAM is *MUCH* faster than HDD) and data volatility (all data on RAM disk is lost when you unplug power or simply restart you computer).

How do I use it

My PC has only 3GB of RAM installed, so I can’t keep everything in RAM. To give the whole idea a shot, I decided to put all Java-related things (Netbeans, JRE, Scala run-time, Tomcat etc.) on RAM disk. The results are *amazing*. Netbeans starts much, much faster. I use nightly builds, so I upgrade and restart the IDE often – that’s also super fast. As for Tomcat or JBoss startup/deployment times, well, you just need to see it yourself :)

In short, here’s how I use it:

  • I keep Netbeans, JDK and other binaries stored on a HDD, RAR’ed with compression level 0 (for speed)
  • I also keep Netbeans settings directory stored separately, in a similar fashion
  • A batch file in my autostart that creates all a RAM disk, and extracts the abovementioned archives to the RAM disk
  • I execute another batch file that whenever I change somehting in my Netbeans config. This batch backs up the new configuration to HDD

I don’t keep any source code on RAM disk, but I might start doing it after I test the whole idea for a little longer.

As you can see, there is some maintenance overhead, but IMHO it’s well worth it. Besides, one could use simpler scenario, supported by the RAM disk tool I use:

  • After system startup, create RAM disk and load an image file
  • Before system shutdown, save RAM disk data to an image file

I stick with archives juggling for testing purposes, but I’ll probably switch to the simpler scenario eventually.

I didn’t really benchmark it, but the experience I’m getting every time I do anything that requires any disk operations is very pleasing.

The tool

I use ImDisk Virtual Disk Driver, written by Olof Lagerkvist. You can download it here (it’s free and open-source). I tried it under Windows XP SP3 and Windows 7, both 32 bit. Author claims that it works on 64 bit systems, but I didn’t have a chance to verify it yet.

In conclusion

I’ve been using the solution described above for couple weeks, and so far I haven’t encountered any problems. The only price I pay for this is longer system start-up time, but I don’t really restart my PC, so it doesn’t matter if it boots 20 seconds longer while I’m making my morning coffee.

So, if you do Java development, especially Java server-side stuff, I strongly encourage you to give RAM disks a try. I’ll say it again – the speed gain is AMAZING :)

P.S. I discovered one nice side effect of the above usage scenario. Like I mentioned, I use nightly builds of different software packages, and sometimes it causes problems. For example, every now and then Netbeans doesn’t run properly after update. Earlier, in such case, I’d simply reinstall the thing. Now I just clean up the RAM disk and restore everything from backup, which takes couple seconds (literally).

Update: Here’s a package with the scripts I mentioned in the post. I don’t use RAM disks this way anymore – SSDs are good enough :)



2 comments

Hi, could you post the details of the batch script that you wrote?
Thanks.
Mathew

Comment by Mathew on 2011/11/02 at 12:35

I posted all the batch files I found. Link’s at the bottom of the post.

Comment by Pawel on 2012/04/30 at 02:59