The crac8 demo should emulate a service that needs to load around 258 000 names from a json file at startup. The "service" provides methods to create a number of random names for either boys or girls. When started normally it will first load the data from the json file into datastructures and then will create 5 random names for girls and 5 random names for boys. This will take around 1-2 sec depending on the machine you run it on. Once you create a checkpoint and restore it from there, the response will only take around 30-50 ms because the data was already loaded from the file and now one can directly access it which leads to the fast "startup" time.
To create the jar file you need to build it on the target platform (Linux x64 or aarch64) using the a JDK that supports CRaC. You can find builds here Azul.
- make sure you set JAVA_HOME to the JVM with CRaC support
- go the project folder
- run
gradlew clean build
- Now you should find the the jar at
build/libs/crac8-17.0.0-fat.jar
- This jar file will later be used to run on the docker container
- Make sure to select the correct JDK in the docker file (x64 or aarch64)
docker login
docker build -t crac8 .
docker commit crac8
docker run -it --privileged --rm --name crac8 hansolo/crac8 java -XX:CRaCCheckpointTo=/opt/crac-files -jar /opt/app/crac8-17.0.0.jar
docker run -it --privileged --rm --name $1 hansolo/crac8:checkpoint java -XX:CRaCRestoreFrom=/opt/crac-files
- Open a shell window
- Run
docker run -it --privileged --rm --name crac8 crac8
- In the docker container run
cd /opt/app
java -XX:CRaCCheckpointTo=/opt/crac-files -jar crac8-17.0.0.jar keeprunning
- Open a second shell window
- Run
docker exec -it -u root crac8 /bin/bash
- Execute
top
command and note the PID of the running java process - Take the PID and run
jcmd PID JDK.checkpoint
- In the first shell window the application should have created the checkpoint
- Check the folder /opt/crac-files for the checkpoint files being present
- In second shell window run
exit
to get back to your machine
- Now get the CONTAINER_ID from shell window 1 by execute
docker ps -a
in shell window 2 - Exit the docker container in shell window 1 by executing
exit
- Run
docker commit CONTAINER_ID crac8:checkpoint
in shell window 2
Now you can start the docker container from the checkpoint by executing
docker run -it --privileged --rm --name crac8 crac8:checkpoint java -XX:CRaCRestoreFrom=/opt/crac-files
- Open a shell window
- Create a text file named
restore_crac8.sh
- Add
#!/bin/bash
echo "docker run -it --privileged --rm --name $1 crac8:checkpoint java -XX:CRaCRestoreFrom=/opt/crac-files"
docker run -it --privileged --rm --name $1 crac8:checkpoint java -XX:CRaCRestoreFrom=/opt/crac-files
- Make the script executable by executing
chmod +x restore_crac8.sh
- Now you can start the docker container multiple times executing
restore_crac8.sh NAME_OF_CONTAINER
If you would like to start the original container without the checkpoint you can still do that by executing the following command
docker run -it --privileged --rm --name crac8 crac8 java -jar /opt/app/crac8-17.0.0.jar