This is an example of Spring Boot Getting Started modified to work on OpenJDK CRaC.
Changes: https://github.com/CRaC/example-spring-boot/compare/base..crac
Use maven to build
mvn package
Please refer to README for details.
- Run the JDK in the checkpoint mode
$JAVA_HOME/bin/java -XX:CRaCCheckpointTo=cr -jar target/spring-boot-0.0.1-SNAPSHOT.jar
- Warm-up the instance
siege -c 1 -r 100000 -b http://localhost:8080
- Request checkpoint
jcmd target/spring-boot-0.0.1-SNAPSHOT.jar JDK.checkpoint
$JAVA_HOME/bin/java -XX:CRaCRestoreFrom=cr
First, we will test CRaC in a Docker environment, then test it in a Kubernetes environment.
Cloud9 will be used for running a sample springboot application restored using CRaC in a Docker container.
- Install OpenJDK CRaC
A JDK that supports CRaC is required. Amazon Corretto is uninstalled, and CRaC JDK is installed to satisfy this requirement.
sudo yum remove java-11-amazon-corretto-headless.x86_64
echo 'export JAVA_HOME=/opt/jdk/openjdk-17-crac+5_linux-x64' >> ~/.bash_profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bash_profile
. ~/.bash_profile
sudo mkdir /opt/jdk/
cd /opt/jdk/
cd $JAVA_HOME
sudo wget https://github.com/CRaC/openjdk-builds/releases/download/17-crac%2B3/openjdk-17-crac+3_linux-x64.tar.gz
sudo tar --extract --file openjdk-17-crac+3_linux-x64.tar.gz --directory .
- Install Maven
cd ~/environment
wget https://dlcdn.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz
tar xzvf apache-maven-3.9.1-bin.tar.gz
echo 'export PATH=/home/ec2-user/environment/apache-maven-3.9.1/bin:$PATH' >> ~/.bash_profile
. ~/.bash_profile
- Setup SSH keys for accessing GitHub, and clone the repository.
ssh-keygen -t ed25519 -C "<your-email-address>"
touch ~/.ssh/config
cat << EOF > ~/.ssh/config
Host github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
EOF
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
cat ~/.ssh/id_ed25519.pub
git clone git@github.com:iamahgoub/example-spring-boot.git
- Build container image, run it, and perform a checkpoint.
DOCKER_BUILDKIT=1 docker build -t example-spring-boot-crac .
docker run --detach --privileged --rm --name example-spring-boot-crac example-spring-boot-crac /opt/scripts/checkpoint.sh
- Confirm that the snapshot has been taken successfully.
docker exec -u root example-spring-boot-crac /opt/scripts/checkpoint-wait.sh
- Use
docker commit
to create a new container image with the checkpoint files included
docker commit example-spring-boot-crac example-spring-boot-crac:checkpoint
- Run a container from the new container image, and restore the Java process from the checkpoint.
docker run --detach --privileged --rm --name example-spring-boot-crac example-spring-boot-crac /opt/scripts/run-service.sh
- Test the restoration by checking logs, and by calling the springboot application HTTP endpoint.
Refer to buildspec.yml
.
Refer to k8s
directory.