Spring Boot on a 256 MB VPS: JDK 25 made the experiment viable
I followed up on my 512 MB Spring Boot VPS experiment by trying the same application on a nominal 256 MiB Alpine VPS.
This is not Hello World. The app uses Spring Boot 3.5.5, MVC/Tomcat, JPA/Hibernate, file-backed H2, Actuator, scheduled GitHub polling, and outbound HTTP. StatLite was running alongside it and polling both Spring and itself.
The JDK 21 setup was too tight. With a 64 MiB heap it suffered severe GC/paging pressure and eventually became unresponsive.
The final JDK 25 configuration was:
-Xms16m
-Xmx80m
-Xss256k
-XX:+UseSerialGC
-XX:TieredStopAtLevel=1
-XX:ReservedCodeCacheSize=32m
-XX:+UseCompactObjectHeadersOn the same nominal 256 MiB VPS, with about 217 MiB visible to Alpine and a 512 MiB swapfile, that configuration completed the full one-hour observation:
- 0 OOM kills
- 0 service restarts
- 72/72 bounded HTTP requests returned 200
- Spring scheduled work continued
- final Spring RSS: ~86 MiB
- StatLite RSS: ~10 MiB
- swap used: 184 MiB

There was still one Hikari Thread starvation or clock leap detected warning with a ~2m13s delay, so I would not call 256 MiB comfortable. For a real deployment I would still start at 512 MB RAM with some swap.
Also, this is not a compact-object-headers benchmark. The JDK version, heap ceiling, and several JVM settings changed together, so I can't attribute the improvement to that flag alone.
Full write-up and reproducible experiment files:
31
u/persicsb Aug 25 '26
And you can even turn it down, if you switch from Spring to a less resource hungry stack. And of course, you can minimize dependencies, loaded beans etc. There is so much to optimize on the default Spring setup.
4
u/Sqirril Aug 25 '26
Man this is just how we run our hundreds of apis in production because they won't give us more ram ;_;
2
u/bobbie434343 Aug 26 '26 edited Aug 26 '26
Could use even less RAM with OpenJ9 as VM (within OpenJDK 25). Maybe at the expense of slightly slower performance, if that is really important. OpenJ9 is really interesting under memory constrained environments.
14
u/Alexx_G Aug 25 '26
I’ve been running in production a medium sized Spring Boot project (Kotlin, MVC, Virtual Threads, Spring Data JDBC, JDK 25) via GraalVM Native Image.
The service has non-trivial functionality (essentially APIs for an ecommerce storefront and management), including image handling etc.
it runs on the smallest AWS Fargate instance (ie 512MB) and stays at about 20% memory usage max, perf tests show decent latency (under 1s) at up to 200rps (autoscaling configured for 100rps) - bottleneck being CPU really.
I’m quite happy with this setup so far.
1
u/MinimallyLoquacious Aug 27 '26
Switch swap from a file to zram, you may be able to stretch it further.
3
u/stjernen Aug 26 '26
If you are resource bound, I would definitely go into Graalvm. Suddenly you experiment with 64 instead of 256.
2
u/Torutofu_Raeva Aug 26 '26
The Hikari "clock leap" warning with 184 MiB of swap in use is almost certainly a swap-in stall rather than a GC pause - the JVM threads get descheduled while pages come back from disk, and it looks identical to a clock jump from inside the process. Worth checking with GC logs plus /proc/<pid>/stat swap and major fault counts side by side, since those two causes need opposite fixes. Lowering vm.swappiness and setting -XX:+AlwaysPreTouch on that small a heap usually cuts the tail latency spikes a lot.
1
u/jonenst Aug 27 '26
Is it reasonable to use C1 only "XX:TieredStopAtLevel=1" ? Or is graal native image a dominant alternative : better perf, lower ram ?
1
u/RadioHonest85 Sep 03 '26
I have some experience running jvm on 256MB kube pod (no spring though), and while you can get a lot done with 256MB and no spring, jemalloc is often required for stable running if traffic is high.
4
u/[deleted] Aug 25 '26
[removed] — view removed comment
1
u/[deleted] Aug 26 '26
[removed] — view removed comment