Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CRaC POC #8743

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<version.lib.gson>2.9.0</version.lib.gson>
<version.lib.grpc>1.60.0</version.lib.grpc>
<version.lib.guava>32.0.1-jre</version.lib.guava>
<version.lib.crac>1.4.0</version.lib.crac>
<version.lib.h2>2.2.220</version.lib.h2>
<version.lib.hamcrest>1.3</version.lib.hamcrest>
<version.lib.handlebars>4.3.1</version.lib.handlebars>
Expand Down Expand Up @@ -812,6 +813,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>${version.lib.jakarta.validation-api}</version>
</dependency>
<dependency>
danielkec marked this conversation as resolved.
Show resolved Hide resolved
<groupId>org.crac</groupId>
<artifactId>crac</artifactId>
<version>${version.lib.crac}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
48 changes: 48 additions & 0 deletions examples/crac/Dockerfile.crac
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
FROM container-registry.oracle.com/os/oraclelinux:9-slim as olinux-crac

WORKDIR /usr/share

ARG CHECKPOINT_DIR

ENV JDK_NAME=zulu22.30.13-ca-crac-jdk22.0.1-linux_x64
ENV JAVA_HOME=/usr/share/$JDK_NAME
ENV CR_DIR=${CONT_IMG_VER:-/crac-checkpoint/cr}

# Install wrk
RUN microdnf -y update && microdnf -y install perl wget tar gzip curl git openssl-devel
RUN git clone https://github.com/wg/wrk.git && cd wrk && make && cp wrk /usr/local/bin/

# Install CRaC
RUN wget -O crac-jdk.tar.gz "https://cdn.azul.com/zulu/bin/${JDK_NAME}.tar.gz"
RUN tar zxf ./crac-jdk.tar.gz -C /usr/share && ln -s $JAVA_HOME/bin/java /bin/
RUN ln -s $JAVA_HOME/bin/jcmd /bin/ && ln -s $JAVA_HOME/bin/jps /bin/

FROM olinux-crac
WORKDIR /helidon

ADD target/*.jar .
ADD target/libs libs
ADD runtimeCRaC.sh .
ADD warmUp.sh .
ADD measure.sh .
RUN chmod +x ./*.sh

CMD ["sh","./runtimeCRaC.sh"]

EXPOSE 7001

41 changes: 41 additions & 0 deletions examples/crac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Helidon MP on CRaC
[Coordinated Restore at Checkpoint](https://wiki.openjdk.org/display/crac)


## Runtime CRaC
Standard docker build doesn't support privileged access to the host machine kernel,
therefore CRaC checkpoint needs to be created in runtime.

```bash
mvn clean package
docker build -t crac-helloworld . -f Dockerfile.crac
# First time ran, checkpoint is created, stop with Ctrl-C
docker run --privileged --network host --name crac-helloworld crac-helloworld
# Second time starting from checkpoint, stop with Ctrl-C
docker start -i crac-helloworld
```

### Exercise the app
```
curl -X GET http://localhost:7001/helloworld
curl -X GET http://localhost:7001/helloworld/earth
curl -X GET http://localhost:7001/another
```

## Kubernetes CRaC

```shell
minikube start
bash deploy-minikube.sh
curl $(minikube service crac-helloworld -n crac-helloworld --url)/helloworld/earth | jq
```

```shell
kubectl get pods
# Check first start - leghtly checkpoint creation
kubectl logs --previous --tail=100 -l app=crac-helloworld
# Check restart - fast checkpoint restoration
kubectl logs -l app=crac-helloworld
# Scale-up quickly
kubectl scale --replicas=3 deployment/crac-helloworld
```
79 changes: 79 additions & 0 deletions examples/crac/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
kind: Service
apiVersion: v1
metadata:
name: crac-helloworld
labels:
app: crac-helloworld
spec:
type: NodePort
selector:
app: crac-helloworld
ports:
- port: 7001
targetPort: 7001
name: http
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: crac-checkpoint
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath:
path: /data/crac-checkpoint/
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: crac-helloworld
labels:
app: crac-helloworld
spec:
replicas: 1
selector:
matchLabels:
app: crac-helloworld
template:
metadata:
labels:
app: crac-helloworld
spec:
containers:
- name: crac-helloworld
image: crac-helloworld
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /crac-checkpoint
name: crac-checkpoint
ports:
- containerPort: 7001
securityContext:
# TODO: be nicer
privileged: true
readinessProbe:
tcpSocket:
port: 7001
initialDelaySeconds: 1
periodSeconds: 1
volumes:
- name: crac-checkpoint
hostPath:
path: /crac-checkpoint
28 changes: 28 additions & 0 deletions examples/crac/deploy-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e
#
# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
eval $(minikube docker-env)
NAMESPACE=crac-helloworld

mvn package -DskipTests
docker build -t crac-helloworld . -f Dockerfile.crac

kubectl delete namespace ${NAMESPACE}
# Cleanup any previous checkpoint
minikube ssh "sudo rm -rf /crac-checkpoint/cr"
kubectl create namespace ${NAMESPACE}
kubectl config set-context --current --namespace=${NAMESPACE}
kubectl apply -f . --namespace ${NAMESPACE}
21 changes: 21 additions & 0 deletions examples/crac/measure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e

#
# Copyright (c) 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

curl --retry 10 --retry-all-errors --retry-delay 1 http://localhost:7001
printf "\nMeasuring ..."
wrk -c 16 -t 16 -d 10s http://localhost:7001
78 changes: 78 additions & 0 deletions examples/crac/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2018, 2024 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../applications/mp/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.microprofile</groupId>
<artifactId>helidon-examples-microprofile-hello-world-implicit</artifactId>
<name>Helidon Examples Microprofile Implicit Hello World</name>

<description>
Microprofile example with implicit bootstrapping (cdi.Main(new String[0])
</description>

<dependencies>
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.logging</groupId>
<artifactId>helidon-logging-jul</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<executions>
<execution>
<id>make-index</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
48 changes: 48 additions & 0 deletions examples/crac/runtimeCRaC.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash -e

#
# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [ ! -d "$CR_DIR" ];
then
echo "==== Creating CRaC checkpoint ===="
echo "=== Checking CRIU compatibility(don't forget --privileged) ==="
$JAVA_HOME/lib/criu check

echo "=== Checking glibc version ==="
# glibc version higher than 2.34.9000-29 are known to have problems with rseq
# on some kernels, workaround GLIBC_TUNABLES=glibc.pthread.rseq=0
ldd --version | grep ldd
# Workaround for https://github.com/checkpoint-restore/criu/issues/1696
# see https://github.com/checkpoint-restore/criu/pull/1706
# export GLIBC_TUNABLES=glibc.pthread.rseq=0

echo "=== Pre-starting Helidon MP app ==="
set +e
mkdir -p "/crac-checkpoint/cr"
./warmUp.sh &
$JAVA_HOME/bin/java -XX:CRaCCheckpointTo=$CR_DIR -jar ./*.jar
set -e

echo "=== CRaC checkpoint created, checking log dump for errors ==="
cat $CR_DIR/dump*.log | grep "Warn\|Err\|succ"
else
echo "==== Starting directly from CRaC checkpoint ===="
./measure.sh &
exec $JAVA_HOME/bin/java -XX:CRaCRestoreFrom=$CR_DIR
fi