Files
asmhatreandClaude Sonnet 5.5 c0062ea398 Add crac module: Spring Boot 4.2 started by CRaC checkpoint/restore vs JDK AOT cache vs native image
One service, seven start-up configurations measured over ten interleaved rounds on Temurin 25, Zulu 25 CRaC and Oracle GraalVM 25;
the open-file checkpoint failure and its fix, stale environment values, secrets in the checkpoint, warp and CRIU engines, cold page cache.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
2026-11-29 13:51:08 +05:30

64 lines
4.0 KiB
Markdown

# crac: one Spring Boot service started four ways
Companion module for the ankurm.com post **Spring Boot with CRaC: Checkpoint/Restore Startup Compared with the JDK AOT Cache and a Native Image**.
No `docs/` folder: this README, the sources and the raw files in [`output/`](output) are the documentation; the explanations live in the post.
## What was tested against
| Thing | Version |
|---|---|
| Spring Boot | 4.2.0 (Spring Framework 7.1.0, Tomcat 11.0.27), `webmvc` + `validation` + `actuator`, no database |
| `org.crac:crac` | 1.5.0 (managed by the Boot 4.2.0 BOM) |
| Plain JVM and AOT cache | Temurin 25.0.5.1+2 (LTS) |
| CRaC JVM | Azul Zulu 25.38.203 with CRaC, `25.0.5.1.1` (LTS) |
| Native image | Oracle GraalVM 25.0.4+7.1, `native-image` 25.0.4, Spring Boot's `native` profile |
| Machine | 2 vCPU, 8 GB, Linux 6.18 (Firecracker VM), running as root. The host was shared with other jobs, so treat milliseconds as indicative and ratios as the result |
## The service
`OrderController` (`/ping`, `POST /orders`, `GET /orders/{id}`), `InfoController` (`/info`: pid, restore count, an environment variable read at start-up and read now),
`RestoreTracker` (a plain `org.crac.Resource`), and three profiles of the audit-log resource:
| Profile | Class | Behaviour |
|---|---|---|
| (none) | - | no file is held open |
| `leaky` | [`LeakyAuditLog`](src/main/java/com/ankurm/crac/LeakyAuditLog.java) | opens a file in the constructor and keeps it: a checkpoint is refused |
| `managed` | [`ManagedAuditLog`](src/main/java/com/ankurm/crac/ManagedAuditLog.java) | opens in `start()`, closes in `stop()`: Spring closes it before the checkpoint and reopens it after the restore |
## Run it
```bash
export JDK_PLAIN=/path/to/temurin-25 JDK_CRAC=/path/to/zulu-25-crac JDK_GRAAL=/path/to/graalvm-25 # defaults are in scripts/env.sh
./scripts/build.sh # jar + extracted layout
./scripts/native.sh # native image (5 to 14 minutes, 5 GB peak)
./scripts/versions.sh # output/01
./scripts/checkpoints.sh # CRaC checkpoints (start-up and warmed-up) and AOT caches; output/02
./scripts/resources.sh # open file, managed file, environment variables, secrets in the image; output/03-05
./scripts/engines.sh # warp and CRIU engines; output/06
./scripts/bench.sh 10 # interleaved rounds of seven start-up configurations; output/08
./scripts/cold.sh 5 # the same with the page cache emptied (root); output/09
./scripts/run-all.sh # everything above, about 25 minutes
```
The scripts use a private port (18771) and a work directory (`/tmp/crac-work`) so they do not collide with other services. Checkpoints, caches and logs live there and are not committed.
## Captured output
| File | Produced by | What it shows |
|---|---|---|
| `01-versions.txt` | `versions.sh` | the exact JDKs, Spring jars and machine |
| `02-create.txt` | `checkpoints.sh` | creating the two checkpoints and two AOT caches: time, size, log lines |
| `03-leaky.txt` | `resources.sh` | `CheckpointOpenFileException`: start-up checkpoint kills the app (exit 1), `jcmd` checkpoint is refused and the app keeps running |
| `04-managed.txt` | `resources.sh` | the fixed file: close/open hooks, Spring's lifecycle restart, the audit file continuing across a restore |
| `05-environment.txt` | `resources.sh` | `System.getenv()` after restore vs a value cached in a field, a new pid, a secret found in `core.img` |
| `06-engines.txt` | `engines.sh` | `warp` and `criuengine` both checkpoint and restore here; what CRIU needs from the process |
| `07-native-build.txt` | `native.sh` (summary of the real build log) | native build time, memory, image size |
| `08-bench.txt` | `bench.sh` | median and range of ten rounds: ready time, first POST, steady state, RSS |
| `09-cold-cache.txt` | `cold.sh` | ready time with an empty page cache |
Timings and RSS differ from run to run; everything else (exceptions, log lines, counts) is stable.
## Things that are not covered
No Docker image was built or run for CRaC; no Kubernetes, no Liberica CRaC JDK, no database or connection pool, and no restore on a different machine or CPU.