DEV Community

BaoKhang
BaoKhang

Posted on Edited on Originally published at baokhang.hashnode.dev AI-assisted

Faster Java Pod Startups Without GraalVM: Why AppCDS Needs Kubernetes Image Volumes

Correction: An earlier version described the Spring Boot image-volume result as 2 seconds (40%) faster based on the difference between separate group medians. The median paired improvement against a plain deployment was 1 second. The readiness timestamps have 1-second resolution.

If you run Java workloads on Kubernetes, you have probably stared at slow pod readiness metrics during a deployment or autoscaling event. The JVM's cold-start work—loading, verifying, and linking thousands of classes—can make scaling painful.

One option is to compile your application into a GraalVM Native Image. This can deliver fast startups, but it can also require longer builds and changes to accommodate closed-world reflection constraints, Java agents, and libraries.

OpenJDK offers a middle ground: Application Class-Data Sharing (AppCDS) on JDK 21+ and Project Leyden AOT caches on JDK 25+. These features let the JVM store prepared class data in an archive on disk for reuse in subsequent runs.

When I started building mnemo-warmup—an open-source tool that automates training and sharing AppCDS/Leyden caches inside Kubernetes without changing application source code—I wanted to answer a simple engineering question:

Does a Kubernetes pod actually become Ready sooner once you pay the infrastructure tax of fetching, verifying, and mounting the cache?

After running hundreds of automated cold-restart benchmarks across different JVM architectures, the answer was: It depends on how you deliver the tooling and what your application does during startup.


The Hidden Infrastructure Tax: Init Containers

One way to deliver a shared cache archive to a stateless pod uses init containers:

  1. An install init container copies the launcher tools onto a shared emptyDir volume.
  2. A fetch init container pulls the trained archive from an OCI registry and verifies its SHA-256 digest.
  3. The main application container boots the JVM pointing to the shared archive.

In practice, measuring the timeline from pod.status.startTime to Ready revealed a bottleneck.

In our initial benchmarks running a heavy Spring Boot application (69 JARs, constrained to 1 CPU / 1 GiB), the AppCDS archive cut the application's reported startup time from 3.18s to 1.88s. Yet the separately calculated median pod readiness times were both 5 seconds.

Even after rewriting our helper utilities from Java into static Go binaries (dropping tool execution time from ~1,050ms to ~140ms), the pod was still losing nearly 1.75 seconds before the main application began. In this setup, init-container lifecycle and orchestration overhead consumed the observed startup savings.

Kubernetes Image Volumes

To reduce the init-container overhead, we tested Kubernetes image volumes (introduced as beta in Kubernetes 1.33+ and supported by containerd 2.1+).

An image volume allows the container runtime to mount the read-only OCI tools layer directly into the application container's filesystem at launch. Our static launcher runs as the entrypoint, fetches the archive directly, and replaces itself with java via exec so the JVM remains PID 1.

Workload Plain deployment (none) Init containers (cached) Image volume (cached) Result
🟢 Spring Boot 5 s 5 s 3 s 1 s faster median paired result with image volumes
🟡 Jenkins LTS (2.492.3) 4 s 5 s 4 s 0 s median paired difference with image volumes
🔴 SonarQube (26.11) 15 s 17 s Not run Init-container arm was slower

The table shows separately calculated group medians over 12 cold restarts on a local kind cluster. The Spring Boot median of the per-round paired differences was −1 second, even though the separate group medians differ by 2 seconds. Kubernetes pod condition timestamps have 1-second resolution, so these readiness measurements are coarse. SonarQube ran with 2 CPU / 3 GiB; the other workloads used 1 CPU / 1 GiB.


Three Lessons on Workload Suitability

Testing three distinct applications illustrated how results can differ across workloads.

1. Framework-Heavy Apps Can Benefit (Spring Boot)

Framework-heavy applications load many classes and perform substantial initialization during startup. In our Spring Boot image-volume test, the application's self-reported startup time fell from a median of 3,182 ms to 1,900 ms with AppCDS.

For pod readiness, the median paired improvement was 1 second against a plain deployment—roughly 20% of the plain group's 5-second median. The separate group medians were 5 seconds and 3 seconds, but subtracting those medians overstates the median paired improvement. The readiness timestamps have only 1-second resolution, so a higher-resolution follow-up would help refine the estimate.

2. I/O and Plugin-Bound Apps Hit Parity (Jenkins)

Jenkins is a large Java application, making it seem like an ideal candidate for AppCDS. However, while the archive successfully loaded 85% of Jenkins' classes and shaved ~300ms off the reported application startup, the median paired pod readiness difference was 0 seconds.

Jenkins startup includes tasks that class-data sharing cannot directly accelerate: unpacking bundled archives, parsing XML configurations on disk, and executing sequential plugin initialization hooks. These activities may limit the impact of class-loading improvements on overall readiness.

3. Multi-Process Wrappers Bypass the Cache (SonarQube)

SonarQube proved to be an important architectural edge case. In our test harness (run at 2 CPU / 3 GiB), training succeeded and all 12 pods validated and loaded the archive. Yet the init-container group's median readiness was 2 seconds slower than the plain group's median.

SonarQube's container entrypoint launches a Java coordinator process, which then spawns separate child JVMs for Elasticsearch, the web server, and the compute engine. Because the wrapper passes -XX:SharedArchiveFile to the parent entrypoint command, the child JVMs do not receive that flag automatically. The image-volume configuration was not tested for this workload.


The Rule of Thumb

If you are evaluating AppCDS or Project Leyden for your Kubernetes clusters, consider these three factors:

  • Check your delivery mechanism: In our tests, init-container overhead offset the startup gains for the Spring Boot workload. Image volumes avoided those init containers and produced a net improvement. Measure the full pod-to-Ready path on your own cluster.
  • Profile your startup bottleneck: Applications that spend substantial time loading classes may benefit, but the pod-level gain depends on the rest of startup and the cache delivery overhead. Workloads dominated by disk I/O, migrations, or network waits may see little benefit. These results do not establish a general percentage improvement for Spring Boot, Micronaut, or other frameworks.
  • Watch out for wrapper scripts: If your container launches a supervisor process that forks downstream child JVMs, those child processes will bypass the cache unless explicitly configured.

What's Next for mnemo-warmup

mnemo-warmup is currently in active alpha. Before tagging our beta, we are running the next wave of studies: comparing JDK 21 AppCDS against JDK 25 Project Leyden AOT archive sizes, mapping out the application size break-even curve (from 40 MB microservices to 350 MB monoliths), and simulating HPA scale-out bursts against remote cloud registries. We also plan to investigate higher-resolution readiness measurements, while accounting for watch delivery latency and readiness-probe timing.

If you want to inspect the raw benchmark CSVs, reproduce the cluster tests on your own hardware, or weigh in on making image volumes our default delivery mode, check out the repository at mnemo-warmup.

Top comments (0)