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.
Join the DZone community and get the full member experience.
Join For FreeYes, 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:
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).
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>.
Check the Build Time in RAM
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
Published at DZone with permission of Dmitry Egorov. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments