Java applications in containers often retain heap memory long after it is needed, preventing the operating system from reclaiming it for other workloads. Dynamic heap memory optimization solves this by periodically returning unused heap memory to the OS. This reduces the memory footprint per application, fits more pod replicas per node in Container Service for Kubernetes (ACK) clusters, and lowers resource costs in Serverless Kubernetes clusters.
How it works
When you enable dynamic heap memory optimization, Enterprise Distributed Application Service (EDAS) adds the -XX:G1PeriodicGCInterval parameter and sets it to 60000 (60 seconds) for applications using the G1 GC policy, adjusting the JVM collection policy to periodically return unused heap memory to the operating system.
EDAS also adjusts the initial heap size (Xms) to 128 MB to maximize the memory range available for dynamic optimization. This creates a wide gap between the initial and maximum heap size, giving the JVM room to scale heap usage up or down based on actual demand.
Requirements
All of the following must be met. The feature cannot be enabled otherwise.
| Requirement | Value | Details |
|---|---|---|
| JDK version | Dragonwell_11_ElasticHeap | Changing the JDK version after enablement automatically disables the feature. |
| GC policy | G1 | Both the Young Generation GC Policy and Old Generation GC Policy must be set to G1. Changing the GC policy after enablement automatically disables the feature. |
| Maximum heap memory | Xmx must be set | The feature requires a defined maximum heap size. |
| Initial heap memory | Xms < Xmx | If Xms equals Xmx, EDAS resets Xms to 128 MB upon enablement. |
Monitoring (optional)
Monitoring is not required for the optimization to work, but provides visibility into memory trends.
| Service | Metrics provided |
|---|---|
| Application Real-Time Monitoring Service (ARMS) | Heap Memory Usage and JVM Memory Usage Trend |
| Managed Service for Prometheus | Pod Memory Usage |
Enable for a new application
Log on to the EDAS console.
In the left-side navigation pane, choose Application Management > Applications. Select a region in the top navigation bar, select a microservices namespace from the Microservices Namespace drop-down list, and then click Create Application.
In the Basic Information step, configure the following parameters:
Parameter Value Cluster Type Kubernetes Clusters Application Runtime Environment Java -- Select Java for a JAR package (Dubbo or Spring Boot). You can reconfigure the Java Environment parameter after you select this option. Select Tomcat for a WAR package (Dubbo or Spring). You can reconfigure the Java Environment and Container Version parameters after you select this option. Java Environment Dragonwell_11_ElasticHeap In the Monitoring and Governance Solution section, select Integrated Solution (Default) and click Next.
In the Configurations step, configure the environment, basic information, deployment mode, and resource parameters, and then click Next.
In the Advanced Settings step, click Edit next to Settings of Java Startup Parameters. In the Edit Java Startup Parameters dialog box:
Set Initial Heap Size and Maximum Heap Memory.
Set both Young Generation GC Policy and Old Generation GC Policy to G1.
Click OK.
Click Dynamic Heap Memory Optimization and turn on Whether to Enable Dynamic Heap Memory Optimization.
Enable for an existing application
Log on to the EDAS console.
In the left-side navigation pane, choose Application Management > Applications. Select a region and namespace, select Container Service or Serverless Kubernetes Cluster from the Cluster Type drop-down list, and then click the target application name.
On the Overview or Basic information page, choose Deploy > Deploy in the upper-right corner.
On the Select Deployment Mode page, select a deployment mode and click Start Deployment.
On the deployment settings page:
Set Application Runtime Environment to Java and Java Environment to Dragonwell_11_ElasticHeap.
Configure the deployment package.
Click Edit next to Settings of Java Startup Parameters. In the Edit Java Startup Parameters dialog box, set Initial Heap Size and Maximum Heap Memory, set both GC policies to G1, and click OK.
Click Dynamic Heap Memory Optimization to view and configure the optimization settings.
Verify the feature is active
Use either method to confirm that the deployment succeeded and dynamic heap memory optimization is in effect:
Change list: Open the Change List page for the application. If Execution status shows Success, the feature is active.
Pod status: On the Application Overview page, click the pod status link next to Running Status. In the Pod section, a green icon in the Status column confirms the application is running with the optimization enabled.
Monitor optimization results
Metrics
EDAS calculates memory usage metrics based on application behavior over the last 15 minutes:
Heap memory usage = Average used heap memory / Average used pod memory (over the last 15 minutes)
Average used heap memory = Mean of JVM heap usage samples collected once per minute over 15 minutes
Average used pod memory = Mean of maximum pod memory samples collected once per minute over 15 minutes
Charts
The optimization dashboard displays memory trends over the last seven days, with one data point per day:
| Chart | What it shows | Data source |
|---|---|---|
| Pod Memory Usage | Pod-level memory consumption | Prometheus |
| JVM Heap | Application heap memory | ARMS |
| JVM Old Generation | Old generation memory | ARMS |
Tune optimization parameters
Default parameter adjustments
When you enable dynamic heap memory optimization, EDAS automatically applies the following adjustments:
| Condition | Adjustment |
|---|---|
| Only Xmx is configured (no Xms) | Xms is set to 128 MB |
| Xmx equals Xms | Xms is reset to 128 MB |
| G1 GC policy is active | -XX:G1PeriodicGCInterval is set to 60000 (60-second periodic GC interval) |
Custom parameters
To reserve more memory for the application and reduce the amount returned to the OS, adjust the heap free ratio parameters. Configure them as custom Java startup parameters. For configuration steps, see Configure Java startup parameters. For parameter details, see Java Documentation.
| Parameter | What it controls | Default | Example |
|---|---|---|---|
MaxHeapFreeRatio | Maximum percentage of idle heap memory allowed before the JVM shrinks the heap | 70% (HotSpot JDK 8, 11, 17) | -XX:MaxHeapFreeRatio=80 |
MinHeapFreeRatio | Minimum percentage of idle heap memory the JVM maintains before expanding the heap | 40% (HotSpot JDK 8, 11, 17) | -XX:MinHeapFreeRatio=50 |
Increasing MaxHeapFreeRatio allows the application to retain more idle heap memory, reducing the frequency of memory release to the OS. Decreasing MinHeapFreeRatio allows the JVM to operate with less free heap before triggering expansion.