r/SpringBoot • u/fykup • 13d ago
Discussion Spring Boot on 256 MiB: OpenJ9 vs HotSpot - is switching JVMs worth it?
I recently compared HotSpot and OpenJ9 on a 256 MiB Linux VM to see whether switching JVMs could reduce Spring Boot's memory footprint without changing the application.
Setup:
- Spring Boot 4.1.1, Spring JDBC, HikariCP, H2
- HotSpot: Eclipse Temurin 25.0.5+8
- OpenJ9: IBM Semeru 25.0.5.0 (OpenJ9 0.63.0)
- Debian 13, 1 vCPU, 256 MiB allocated, swap enabled
- Same application, 80 MiB max heap
Spring Boot under load (median RSS + median swap):
- HotSpot: 118.6 + 70.6 = 189.2 MiB
- OpenJ9: 121.9 + 19.4 = 141.3 MiB
- Difference: ~48 MiB (25% lower)
Important distinction: these are RSS + swap figures, not physical RAM usage. Interestingly, OpenJ9 had slightly higher resident RSS but substantially less swap.
Startup was another interesting observation:
- HotSpot: 10 seconds to readiness
- OpenJ9: 21 seconds to readiness
However, these were single cold-start runs. OpenJ9's shared class cache was initially empty, and we haven't measured warm-cache startup for Spring Boot. So I wouldn't draw conclusions about startup performance yet.
This was a short exploratory experiment with roughly 45 seconds of read-only load at 4.5 requests/sec, not a comprehensive JVM benchmark.
Full experiment and results:
https://pvrlabs.xyz/java-performance/experiments/openj9-vs-hotspot-256mb.html
And a funny coincidence: the recent Java4Shell vulnerability involves a HotSpot-specific Base64 optimization that OpenJ9 doesn't use. Sometimes being the underdog has its perks. :)
Has anyone used OpenJ9 for production Spring Boot services? I'm particularly interested in whether you've observed similar memory behavior, and how startup performance changes with a warmed shared class cache.
Also curious whether tuning HotSpot would narrow the gap enough to make switching JVMs unnecessary.
Raw measurements and methodology:
https://github.com/PVRLabs/experiments/tree/main/java/coilbase-debian-256
1
u/tanglewood36 12d ago
curious why swap was enabled for the benchmark? usually with tight memory constraints you want swap off so you can see where the actual OOM boundary sits under sustained load.
1
u/sereikis 13d ago
before switching JVMs, measure p95/p99 latency and major page faults during a longer run at the same offered load. less swap allocated does not necessarily mean less active paging; comparing those alongside RSS would show whether the memory difference actually improves service under pressure.
1
u/FriendshipCalm3162 12d ago
HotSpot has had its own shared class cache since JDK 24, and it's off by default, so your Temurin run is competing against a feature you only gave OpenJ9. The AOT cache from JEP 483 is in 25, and JEP 514 cut creating it down to one flag:
-XX:AOTCacheOutput=app.aoton a training run, then-XX:AOTCache=app.aotin production. The archive gets memory-mapped read-only, so class metadata that would otherwise sit in anonymous metaspace becomes file-backed clean pages, and the kernel can drop those instead of writing them to swap. Given that the whole 48 MiB is swap, that's the first thing I'd try before changing JVMs.The catch on a 256 MiB box is that the one-step creation forks a second JVM sized to the same heap, so peak memory roughly doubles while the cache is being built. The Java team's own suggestion is to do the training run on the small instance and assemble the cache on a bigger one.
GC flags aren't the lever here either. With 1 vCPU, ergonomics already picks SerialGC on both JVMs, since Serial gets selected below 2 CPUs or 1792 MB, so the usual "try Serial" advice is a no-op for you.
For the 118 MiB of RSS against an 80 MiB heap, I'd run
-XX:NativeMemoryTracking=summarywithjcmd VM.native_memorybefore tuning anything, since that splits it into heap, metaspace, code cache, thread stacks and compiler scratch. On a small box with Spring Boot the two that usually dominate are Tomcat's 200 max threads and C2's working memory, andserver.tomcat.threads.maxplus-XX:TieredStopAtLevel=1are both one-line tests./proc/<pid>/smaps_rollupwill also give you Swap and Private_Dirty per process, which beats adding RSS and swap together.