All Products
Search
Document Center

Serverless App Engine:JVM configuration reference

Last Updated:Dec 11, 2025

Learn how to configure JVM stack memory and optimize memory usage to avoid OOM issues.

Configuration reference of stack memory

JVM configuration reference

The following configuration values are for reference only. Adjust the values based on stress tests to optimize system performance.

JVM configuration item

Description

1C 2G

2C 4G

4C 8G

8C 16G

-Xms

The initial size of the heap memory

1G

2560M

4G

10G

-Xmx

The maximum size of the heap memory

1G

2560M

4G

10G

-Xmn

The size of the young generation space

500M

1200M

2G

5G

-Xss

The size of the thread stack space (Default value for JDK 8: 1M)

1M

1M

1M

1M

-XX:MetaspaceSize

The initial size of the metaspace

128M

256M

384M

512M

-XX:MaxMetaspaceSize

The maximum size of the metaspace

128M

256M

384M

512M

-XX:MaxDirectMemorySize

The maximum size of the off-heap memory

256M

256M

1G

1G

-XX:ReservedCodeCacheSize

The size of the code cache

64M

128M

256M

256M

Typical configuration parameters for heap and stack size

Configuration parameter

Description

Example

-Xmx

Sets the maximum heap size.

-Xmx3550m, sets the maximum available memory for the JVM to 3550 MB.

-Xms

Sets the minimum heap size.

-Xms3550m, sets the initial memory for the JVM to 3550 MB. We recommend that you set this option to the same value as -Xmx to prevent the JVM from reallocating memory after each garbage collection.

-Xmn

Sets the size of the young generation.

-Xmn2g, sets the size of the young generation to 2 GB. Total JVM heap size = Size of the young generation + Size of the old generation + Size of the permanent generation. In most cases, the permanent generation has a fixed size of 64 MB. Therefore, if you increase the size of the young generation, the size of the old generation is reduced. The value of -Xmn significantly affects system performance. We recommend that you set this option to 3/8 of the total heap size.

-Xss

Sets the stack size of the thread.

-Xss128k, sets the stack size of each thread to 128 KB.

Note

If you use JDK 5.0 or later, set this option to 1 MB. If you use earlier JDK versions, set this option to 256 KB. You can adjust the stack size of each thread based on your business requirements. With the same physical memory size, a smaller value for this option allows more threads. The number of threads in a process is limited by your operating system. In most cases, a process can have 3,000 to 5,000 threads.

-XX:NewRatio=n

Sets the ratio of the young generation to the old generation.

-XX:NewRatio=4, sets the ratio of the young generation (including Eden and two Survivor spaces) to the old generation (excluding the permanent generation). In this case, the young generation occupies 1/5 of the heap.

-XX:SurvivorRatio=n

Specifies the ratio of the eden space to the two survivor spaces in the young generation.

-XX:SurvivorRatio=4, sets the ratio of the eden space to the survivor spaces in the young generation. In this case, each survivor space occupies 1/6 of the young generation.

-XX:MaxPermSize=n

Sets the maximum size of the permanent generation.

-XX:MaxPermSize=16m, sets the size of the permanent generation to 16 MB.

-XX:MaxTenuringThreshold=n

Sets the age of the objects in the young generation.

-XX:MaxTenuringThreshold=0, sets the maximum age of garbage.

  • In this case, the objects in the young generation bypass the survivor spaces and overflow directly into the old generation. This improves the efficiency of applications whose old generation sizes are large.

  • If you set this option to a large value, the objects in the young generation are copied multiple times in the survivor spaces. This increases the period of time during which the objects stay in the young generation. In addition, frequent garbage collection may occur in the young generation.

Configure garbage collectors

Typical configuration parameters for throughput-oriented GC

Configuration parameter

Description

Example

-XX:+UseParallelGC

Instructs the JVM to use the parallel GC for the young generation.

-Xmx3800m -Xms3800m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20, -XX:+UseParallelGC This configuration is effective only for the young generation. In this example, the young generation uses concurrent collection, while the old generation still uses serial collection.

-XX:ParallelGCThreads

Specifies the number of threads that can be used simultaneously by the parallel GC for garbage collection.

Note

We recommend configuring this value to equal the number of processors.

-Xmx3800m -Xms3800m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20, -XX:ParallelGCThreads=20 indicates that the number of threads for the parallel collector is set to 20.

-XX:+UseParallelOldGC

Instructs the JVM to use the parallel GC for the old generation.

Note

If you use JDK 6.0, you can select the parallel GC for the old generation.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC, -XX:+UseParallelOldGC indicates that the parallel collection is used for the old generation.

-XX:MaxGCPauseMillis

Sets the maximum pause time of each garbage collection for the young generation. The JVM automatically adjusts the size of the young generation to maintain the value of this option.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:MaxGCPauseMillis=100, -XX:MaxGCPauseMillis=100 sets the maximum pause time of each garbage collection for the young generation to 100 ms.

-XX:+UseAdaptiveSizePolicy

Enables the adaptive size policy. If you configure this option, the parallel GC automatically adjusts the size of the young generation and the ratio of the Survivor spaces to achieve the best latency or optimal garbage collection frequency. We recommend that you always enable the adaptive size policy for the parallel GC.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:MaxGCPauseMillis=100 -XX:+UseAdaptiveSizePolicy

Typical configuration parameters for response time-oriented GC

Configuration parameter

Description

Example

-XX:+UseConcMarkSweepGC

Instructs the JVM to use the concurrent mark sweep (CMS) GC for the old generation.

Note

If you configure -XX:+UseConcMarkSweepGC, we recommend that you use -Xmn to set the size of the young generation.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC

-XX:+UseParNewGC

Specifies the parallel GC for the young generation.

The parallel GC and the CMS GC can be used for the young generation at the same time. If you use JDK 5.0 or later, the JVM automatically configures this option based on your system configurations. In this case, you do not need to configure this option.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC

-XX:CMSFullGCsBeforeCompaction

The CMS GC does not compact or manage the heap space. Therefore, fragmentation occurs after the CMS GC runs for a specific period of time. As a result, the running efficiency of applications may decrease. This option specifies the number of times that a CMS GC must run through the heap before the heap space is compacted or managed.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection, -XX:CMSFullGCsBeforeCompaction=5, indicates that the heap space is compacted or managed after the GC runs 5 times.

-XX:+UseCMSCompactAtFullCollection

Enables the compaction for the old generation heap.

Note

If you enable this option, the fragmentation problem can be prevented, but the system performance may be degraded.

-Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection

Typical configuration parameters for auxiliary GC

Configuration parameter

Description

-XX:+PrintGC

The option to print GC logs.

-XX:+PrintGCDetails

The option to print GC details.

-XX:+PrintGCTimeStamps

The option to print the GC timestamp from the time when the JVM starts up to the current date. See the following example:

0.855: [GC (Allocation Failure) [PSYoungGen: 33280K->5118K(38400K)] 33280K->5663K(125952K), 0.0067629 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]

-XX:+PrintGCDateStamps

The option to print the GC timestamp as a date. See the following example:

2022-01-27T16:22:20.885+0800: 0.299: [GC pause (G1 Evacuation Pause) (young), 0.0036685 secs]

-XX:+PrintHeapAtGC

The option to print the heap information before and after garbage collection.

-Xloggc:../logs/gc.log

The option to specify the output path of the log files.