Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Accelerating Build Using a RAM Disk

DZone's Guide to

Accelerating Build Using a RAM Disk

Learn how to speed up your build time using RAM memory as a filesystem, on Windows or Linux, in this quick tutorial.

· Performance Zone ·
Free Resource

Yes, RAM memory can be used as a filesystem! RAM memory, in comparison with a regular drive, has these advantages:

  • Fast IO operations
  • Fast search operations
  • Less number of junks
  • Reduced fragmentations
  • No noise or heat

But, of course, it has disadvantages:

  • Losing memory on reboot
  • High price
  • Size limit

When Is Sacrificing RAM Memory Reasonable?

  • To decrease the time of your builds/compilers.
  • To speed up your database.
  • Cache, cache, cache.
  • To accelerate heavy applications like CAD, development IDEs, or even games.

Windows RAM Drive Applications

Linux RAM Drive

To allocate RAM in Linux, you need to take two steps:

Create a folder:

 mkdir /mnt/myramfolder

Mount RAM:

mount -t [TYPE] -o size=[SIZE] [FSTYPE] [MOUNTPOINT]


Now, let's take a look at an example.

Using RAM Memory to Speed Up Build in Java Maven-Based Projects

Allocating 2GB disk using ImDisk application and mount it to G disk:

Image title

Fetching a random Java project from GitHub (Guava): https://github.com/google/guava.

Building that project using the Maven command:

mvn clean install -DskipTests -Dmaven.javadoc.skip=true

Checking the results with a hard drive very performant SSD: Samsung EVO 960 (2GB/3GB read/write speed).

Image title

Building the Project Using a RAM Disk

Put an .m2 Maven repository and Guava project in a RAM drive. Maven requires you to change the .m2 location in settings file to <localRepository>G:/.m2</localRepository>.

Image title

Check the Build Time in RAM

Image title

Results: the RAM disk saved 37% of the build time.

That's pretty good, considering that we are comparing a very performant SSD with regular RAM. Results should be better for non-SSD hard drives. If we go deeper, then the next step is to put the whole Linux machine in RAM.

How to Save Your RAM Disk Before Reboot

In Windows, ImDisk provides a storing feature from the box.

In Linux, you need to write a small script with recursive saving files, like so:

cp -avr /mnt/myramfolder /tmp/myrambackup
Topics:
performance ,java ,build ,ram ,optimization ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}