Configure JVM memory parameters for applications monitored by Application Real-Time Monitoring Service (ARMS). Use these recommended values as a starting point and adjust them based on your stress testing results.
Total memory budget
Total JVM memory must not exceed 80% of the server's physical memory. The remaining 20% is reserved for the operating system, thread stacks, and JVM internals.
Total JVM memory is the sum of four regions:
Heap (
-Xms,-Xmx,-Xmn) -- stores objects and runs garbage collection. Heap size is primarily influenced by application throughput.Metaspace (
-XX:MetaspaceSize,-XX:MaxMetaspaceSize) -- stores class metadata. Metaspace size depends on the number of classes your application loads.Off-heap (direct) memory (
-XX:MaxDirectMemorySize) -- used by NIO buffers and third-party libraries. Direct memory size depends on throughput and use of libraries such as NIO and gzip.Code cache (
-XX:ReservedCodeCacheSize) -- stores JIT-compiled native code.
Recommended values by server specification
-Xms is set equal to -Xmx to prevent pauses caused by heap resizing at runtime.
| JVM parameter | Description | 1C 2G | 2C 4G | 4C 8G | 8C 16G |
|---|---|---|---|---|---|
-Xms | Initial heap size | 1G | 2560M | 4G | 10G |
-Xmx | Maximum heap size | 1G | 2560M | 4G | 10G |
-Xmn | Young generation size | 500M | 1200M | 2G | 5G |
-Xss | Thread stack size (JDK 8 default: 1M) | 1M | 1M | 1M | 1M |
-XX:MetaspaceSize | Initial metaspace size | 128M | 256M | 384M | 512M |
-XX:MaxMetaspaceSize | Maximum metaspace size | 128M | 256M | 384M | 512M |
-XX:MaxDirectMemorySize | Maximum off-heap memory size | 256M | 256M | 1G | 1G |
-XX:ReservedCodeCacheSize | Code cache size | 64M | 128M | 256M | 256M |
Note: These values are recommendations. Validate them through stress testing with your actual workload before deploying to production.
Sizing ratios
The recommended values follow these ratios:
Heap (
-Xmx): approximately 50--65% of total server memory, leaving room for non-heap regions and the OS.Young generation (
-Xmn): approximately 50% of the maximum heap size. If you use the G1 garbage collector, consider omitting-Xmn-- G1 manages young generation sizing automatically.Metaspace:
MetaspaceSizeis set equal toMaxMetaspaceSizeto avoid dynamic resizing overhead. Scale the value based on the number of classes your application loads.
Common misconfigurations
| Misconfiguration | Impact |
|---|---|
-Xmx too high (total JVM memory exceeds physical memory) | The OS swaps to disk, causing latency spikes, or terminates the JVM process (OOM killer). |
-Xmn too large relative to -Xmx | Insufficient space for the old generation triggers frequent full garbage collections. |
-XX:MaxMetaspaceSize too low | java.lang.OutOfMemoryError: Metaspace occurs when the application loads many classes (common with Spring or reflection-heavy frameworks). |
-Xms lower than -Xmx | The JVM resizes the heap at runtime, causing pauses. Set both to the same value. |