際際滷

際際滷Share a Scribd company logo
Project CRaC
Coordinated Restore at Checkpoint
Goran eko
What the CRaC?!
2
Coordinated Restore at Checkpoint (CRaC)
on the Java Virtual Machine
https://openjdk.org/projects/crac
OpenJDK vs Project CRaC
OpenJDK is a place, not a thing (73 projects)
Source code for the Java Development Kit:
 Virtual Machine (HotSpot)
 Java Class Library
 Java Compiler (javac)
Project CRaC
 Proposed and led by Azul
 OpenJDK Zulu builds (binary distributions) by Azul include CRaC features
 OpenJDK vs builds is like Linux vs its distributions
3
How does JVM work?
4
5
Execution Cycle
6
Startup vs Warmup
Checkpoint & Restore concepts
7
CRaC API
 Coordination - ability to react on before and after events (resource management)
 The API enables coordination of resources during checkout and restore
 Checkpoint and restore notifications, awareness of checkpoint/restore events (callbacks)
 Java frameworks and libraries are adopting CRaC, eg. Apache
 CRaC implementation creates the checkpoint safely
 Ensures reliable restart from a given checkpoint
 org.crac dependency
8
Resource & Context
public class MyResource implements Resource {
public MyResource() {
org.crac.Core.getGlobalContext().register(this);
}
@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
// free your resources
}
@Override
public void afterRestore(Context<? extends Restore> context) throws Exception {
// load your resources
}
}
9
Benefits
 Provides immediate application start with peak performance
 Faster deployment process as well
 Eliminates JIT compilation overhead or JVM warm-up
 Hotspot identification, method compiles, recompiles and deoptimisations
 Reduces costs in cloud/K8s environments (pay-as-you-use)
 When scaling resources to meet demand
 Less time and computing resources used
 Ideal for apps that perform a lot of work during startup & warmup
 Major frameworks are supported: Micronaut, Quarkus and Spring (Boot)
10
Limitations
1. No auto-dump for open files and sockets
(we need to take care of that)
2. Must be restored on the same architecture
(Linux x64,Arm64 | JDK 17 & 21 Azul Zulu builds of OpenJDK)
3. Changes in the value of the system clock (time difference)
(for syncing or caching)
11
CRaCs summary
12
+
-
GraalVM Native Images - Ahead-of-Time
 Ahead of Time is static compilation
 Native instructions give full speed from the start
 No need to start the app ahead of time
 No CPU overhead to compile code at runtime
 3x smaller memory consumption
 Smaller image than the snapshot
13
 All classes must be available at build time
 No JIT (runtime) compilation optimisations
 Lower performance than JIT optimised JVM
 Debugging is harder
How fast is it?
14
* Proof of concept results
How to Checkpoint/Restore?
15
JVM CRaC parameters
# START
$ java -XX:CRaCCheckpointTo=/crac-files -jar app.jar
# CHECKPOINT
$ jcmd <PID>/app.jar JDK.checkpoint
$ Core.checkpointRestore();
# RESTORE
$ java -XX:CRaCRestoreFrom=/crac-files
16
Demo Time
CRaC in Action
17
Deployment example
18
19
Thank you.
Java: the elegant simplicity of C++ and the
blazing speed of Smalltalk.
James Gosling
https:/
/openjdk.java.net/projects/crac/
https:/
/github.com/crac

More Related Content

Project CRaC

  • 1. Project CRaC Coordinated Restore at Checkpoint Goran eko
  • 2. What the CRaC?! 2 Coordinated Restore at Checkpoint (CRaC) on the Java Virtual Machine https://openjdk.org/projects/crac
  • 3. OpenJDK vs Project CRaC OpenJDK is a place, not a thing (73 projects) Source code for the Java Development Kit: Virtual Machine (HotSpot) Java Class Library Java Compiler (javac) Project CRaC Proposed and led by Azul OpenJDK Zulu builds (binary distributions) by Azul include CRaC features OpenJDK vs builds is like Linux vs its distributions 3
  • 4. How does JVM work? 4
  • 7. Checkpoint & Restore concepts 7
  • 8. CRaC API Coordination - ability to react on before and after events (resource management) The API enables coordination of resources during checkout and restore Checkpoint and restore notifications, awareness of checkpoint/restore events (callbacks) Java frameworks and libraries are adopting CRaC, eg. Apache CRaC implementation creates the checkpoint safely Ensures reliable restart from a given checkpoint org.crac dependency 8
  • 9. Resource & Context public class MyResource implements Resource { public MyResource() { org.crac.Core.getGlobalContext().register(this); } @Override public void beforeCheckpoint(Context<? extends Resource> context) throws Exception { // free your resources } @Override public void afterRestore(Context<? extends Restore> context) throws Exception { // load your resources } } 9
  • 10. Benefits Provides immediate application start with peak performance Faster deployment process as well Eliminates JIT compilation overhead or JVM warm-up Hotspot identification, method compiles, recompiles and deoptimisations Reduces costs in cloud/K8s environments (pay-as-you-use) When scaling resources to meet demand Less time and computing resources used Ideal for apps that perform a lot of work during startup & warmup Major frameworks are supported: Micronaut, Quarkus and Spring (Boot) 10
  • 11. Limitations 1. No auto-dump for open files and sockets (we need to take care of that) 2. Must be restored on the same architecture (Linux x64,Arm64 | JDK 17 & 21 Azul Zulu builds of OpenJDK) 3. Changes in the value of the system clock (time difference) (for syncing or caching) 11
  • 13. GraalVM Native Images - Ahead-of-Time Ahead of Time is static compilation Native instructions give full speed from the start No need to start the app ahead of time No CPU overhead to compile code at runtime 3x smaller memory consumption Smaller image than the snapshot 13 All classes must be available at build time No JIT (runtime) compilation optimisations Lower performance than JIT optimised JVM Debugging is harder
  • 14. How fast is it? 14 * Proof of concept results
  • 16. JVM CRaC parameters # START $ java -XX:CRaCCheckpointTo=/crac-files -jar app.jar # CHECKPOINT $ jcmd <PID>/app.jar JDK.checkpoint $ Core.checkpointRestore(); # RESTORE $ java -XX:CRaCRestoreFrom=/crac-files 16
  • 17. Demo Time CRaC in Action 17
  • 19. 19 Thank you. Java: the elegant simplicity of C++ and the blazing speed of Smalltalk. James Gosling https:/ /openjdk.java.net/projects/crac/ https:/ /github.com/crac