Troubleshooting Excessive Memory Usage in Spring Boot Microservices and JVM Parameter Best Practices
This article recounts a production incident where Spring Boot services consumed excessive memory, details step‑by‑step diagnostics using jps and jmap, explains default JVM heap settings, offers remediation recommendations, and also includes promotional material for AI services.
Hello everyone, I am a top architect.
In a production environment we encountered a problem where each SpringBoot microservice consumed nearly 12 GB of memory on a 64 GB server, causing the services to become unresponsive as business load increased.
Background
After the system went live it ran smoothly at first, but as traffic grew the Java applications started using excessive memory. Since the project uses a micro‑service architecture with multiple SpringBoot instances, the total memory quickly ran out.
Solution Steps
step1: Use jps or top to view process IDs.
step2: Run jmap -heap <PID> to inspect heap configuration.
The output shows that the maximum heap size was set to 4 GB, while the production server had 64 GB of physical memory, allowing each JVM to allocate up to 12 GB.
-Xmx (maximum heap size) is usually set to about one‑quarter of physical memory.
-Xms (initial heap size) is usually set to about one‑sixty‑fourth of physical memory.
According to Oracle’s official JVM defaults, unless explicitly set, the initial and maximum heap sizes are calculated based on the amount of RAM.
Client JVM defaults : maximum heap is half of physical memory if RAM ≤ 192 MB, otherwise one‑quarter if RAM ≤ 1 GB.
Server JVM defaults : on 32‑bit JVMs with ≥ 4 GB RAM the max heap can reach 1 GB; on 64‑bit JVMs with ≥ 128 GB RAM the max heap can reach 32 GB.
In this case the operations team launched the SpringBoot applications without custom JVM parameters, relying on the defaults, which caused each service to reserve far more memory than needed.
Recap
General steps for investigating high memory usage:
Check JVM parameters : Ensure appropriate -Xms and -Xmx values are set for production workloads.
Monitor memory usage : Use OS tools or monitoring platforms to observe heap, non‑heap, and GC activity.
Analyze GC logs : Look for frequent collections or long pause times.
Set reasonable heap size : Align heap size with application demand and server capacity.
Use profiling tools : Tools like VisualVM or MAT can detect memory leaks or large objects.
Running SpringBoot without proper JVM tuning can lead to wasted resources, potential out‑of‑memory errors, and degraded performance.
Promotional Section (Non‑Technical)
We also invite readers to join our AI community where we share ChatGPT usage tips, side‑hustle ideas, and provide free ChatGPT accounts, tutorials, and premium resources for a limited time.
For more details, visit the links provided in the original article.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.