We are happy to announce the feature release of Liberica JDK LTS versions 17 and 21 with Coordinated Restore at Checkpoint (CRaC) support, enabling the developers to make running application snapshots and reduce the startup and warmup time of Java application to mere milliseconds!
As opposed to other methods of reducing startup and warmup time, such as Application Class Data Sharing (AppCDS) and AOT compilation, CRaC helps to achieve instant startup at peak performance without losing the ability to further optimize performance with JIT compiler.
The new builds will be available for x86_64 и AArch64 CPU architectures and Linux operating system.
Before diving into experiments with JVM with CRaC, let’s discuss the functionality in more detail to get a clearer picture of its capabilities and specifics.
Table of Contents
- What is Coordinated Restore at Checkpoint (CRaC)?
- Spring Boot and Liberica JDK with CRaC — made for each other!
- Which applications need CRaC
- Main considerations when using CRaC
- Download the new Liberica JDK builds with CRaC and start experimenting!
What is Coordinated Restore at Checkpoint (CRaC)?
CRaC offers Java developers a Checkpoint/Restore API to create an image of a running application at an arbitrary point in time (“checkpoint”), and then start the image from the checkpoint file (snapshot), restoring the state of an application from the point when the checkpoint was made. Essentially, you pause the application and restart it from the moment it was paused, and in addition, you can distribute numerous replicas of this file, which is especially relevant for deployment on multiple instances.
Coordinated processes for enhanced reliability
Coordinated Checkpoint/Restore makes the application aware of the fact that it is being paused and restarted. This way, the application can cancel the checkpoint if it deems the moment unsuitable for saving the state (when it performs certain operations such as saving the user data, for example). In addition, it can perform essential preliminary tasks, such as closing network connections and open file descriptors, and then return to normal operation after restore and react to possible changes in the environment since the checkpoint.
CRIU vs CRaC
CRIU (Checkpoint and Restore in Userspace) is a technology for Linux that serves as a foundation for CRaC. CRIU uses ptrace kernel interface and allows for freezing a running application and restoring it from the saved checkpoint files. The existing OpenJDK CRaC implementation includes CRIU and adds several enhancements and adjustments tailored to Java applications. Namely, CRaC imposes more restrictions on the restore process. For instance, CRIU can save the state of a TCP socket and then restore the connection. With CRaC, all connections must be closed before checkpoint, which makes the whole process more reliable.
Spring Boot and Liberica JDK with CRaC — made for each other!
Spring Boot currently integrates with CRaC as a Proof-of-Concept, the in-baked support is planned in future releases. Thanks to CRaC support, Liberica JDK, the default runtime for Spring, will help developers on their journey towards smooth integration of the functionality into their Spring Boot projects so that they can enjoy unprecedented startup and warmup speed with minimal code rewriting.
We already tested CRaC-ed Liberica JDK with Spring Boot Petclinic, and the results are amazing! Time to first operation reduced from 7.1 seconds to 54 milliseconds without additional configuration!
- CPU: Intel(R) Xeon(R) CPU X5675 @ 3.07GHz,
- JDK: Liberica JDK 17.0.8,
- OS: Linux Ubuntu 22.04.1.
Spring Boot Petclinic and Liberica JDK with CRaC: startup study results
Which applications need CRaC
The CRaC is most beneficial for applications characterized by
- short runs,
- frequent restarts,
- low CPU limits, and
- deployment to multiple replicas.
If developers allocate too little memory to their instances, the application starts up slowly, leading to increased costs, especially If the enterprises use cloud services where they pay for the time your code executes. But if the instances are too large, companies overpay for resources that are never utilized. In addition, when a Java application goes through the standard startup and warmup processes, the CPU consumption tends to be higher than in the stabilized state.
However, in the case of using CRaC, applications will start almost instantly and at peak performance, minimizing the latency and optimizing resource consumption.
Main considerations when using CRaC
CRaC represents a stateful approach as it preserves the exact state of a running application at a given time, together with information about the Java heap, native memory, JIT-compiled code, settings, etc. As a result, the snapshot may contain secrets and other kinds of sensitive data. Developers should keep that in mind when working with the technology and either assess carefully how the snapshot files are made, stored, and accessed, or perform checkpoint at the moment when JVM doesn’t store any sensitive information.
In addition, developers must keep in mind possible issues with randomness. As the
java.util.Random seed is created upon initialization, the pseudo-random numbers upon restore will be predictable. You can create a new seed in an
afterRestore() method, but the best solution is to use
java.security.SecureRandom that provides more reliable random numbers generation. With SecureRandom, developers can clean the SecureRandom seed (together with NativePRNG) and lock the random operations before taking the snapshot. The lock is removed in an
afterRestore() method. This guarantees the safe random number generation after snapshot restoration.
Curious to know how to use CRaC with Java apps and Spring Boot projects? Head to our tutorial with step-by-step instructions!
Download the new Liberica JDK builds with CRaC and start experimenting!
CRaC is an open-source OpenJDK project, so Liberica JDK with CRaC is free for use. Liberica JDK with CRaC support can currently be used on bare metal and in virtual machines. Support for containerized workloads is in the makings.
Please note that OpenJDK builds with CRaC, including Liberica JDK, are not yet verified by TCK. So you can experiment with the functionality, see how it fits into your workloads and how it benefits your project. The information about new Liberica JDK builds with CRaC support will also be available via Discovery API.
To get started with the feature, you can visit the official GitHub CRaC repository or read the online documentation on the OpenJDK page of the project, which includes hardware and software requirements, guides on configuring the JDK, troubleshooting tips, and so on. You can also consult BellSoft engineers, and we will be happy to help!