Ramdisk doesn't benefit Maven Builds
For years I've heard of people moving beyond SSDs and using ramdisks for maven builds, in an attempt to decrease build times. In my experimentation, however, I saw no benefit over a typical consumer SSD from the early 2020's.
Procedure
I allocated 1GB of RAM to a ramdisk. The compiled project size was significantly smaller than this, so the ramdisk could completely hold the build artifacts.
sudo mount -t tmpfs -o size=1g ramdisk /tmp/build
I instructed maven to use the /tmp/build folder for temporary files via my project's pom.xml
:
<build>
<directory>${custom.build.directory}</directory>
</build>
<properties>
<custom.build.directory>/tmp/build/${project.groupId}-${project.artifactId}/target</custom.build.directory>
Then I ran tests comparing the build performance before and after the change.
Outcome
There was no repeatable difference in build times on a medium-sized project (~10K LOC).
Future Work
This effort moved the target
folder to the ramdisk. For a build, that moves some of the heaviest and largest writes into the ramdisk. However, other files might also benefit from being on the ramdisk:
- Source code
- Risky — has to be copied off the ramdisk to permanent storage before next reboot
- Maven repository
- Maybe a quick rsync from the SSD-based repo would be a quick way to set it up.
Last modified on 3 Oct 2024 by AO
Copyright © 2024 Andrew Oliver