Video in progress
Someone proposed moving a long-running, high-load API service to GraalVM native image. How do you evaluate it?
In a long-running service, native image's main benefit, fast startup, hardly matters, while peak throughput and diagnostic capabilities may be lost. I measure memory savings and operational cost, and then decide.
📖 Answer
Native image is good technology, but it solves a different problem. This is how I weigh it.
What we gain:
- startup of around 100 ms instead of several seconds;
- RSS is often 2-3 times lower (no metaspace, JIT or code cache);
- a smaller container image.
What we lose:
- C2's profile-guided optimization. In a long-running service the JIT often gives a better peak. PGO (in Oracle GraalVM) narrows the gap, but collecting the profile adds another stage to the build;
- a limited choice of GC (Serial, and G1 only on certain distributions and on Linux);
- diagnostics: JFR and heap dumps are supported, but JVMTI agents (many APM tools) don't work, and
jcmdcapabilities are narrower; - the "closed world": metadata for reflection, dynamic proxies and classpath scanning. Spring Boot 3 AOT handles much of this, but every new library is a risk;
- build time: 5-10 minutes in CI and 8+ GB of RAM.
To decide, I measure three things under the same load: steady-state p99, CPU per request, and RSS per pod. If native image saves 60% of memory and p99 doesn't change, on a fleet of 300 pods that is a lot of money, and the move is worth it. If throughput drops 20%, the saved memory is eaten by the extra pods and the benefit disappears. The answer is often mixed: small functions that scale fast go native, and heavy APIs stay on the JVM.
Sign up to mark studied questions and save your progress.