When you create or deploy an application in a Container Service for Kubernetes (ACK) cluster or a Serverless Kubernetes cluster, you can enable the dynamic heap memory optimization feature to improve the heap memory usage of the application based on the application memory usage threshold. The dynamic heap memory optimization feature can not only improve the memory utilization of a single application, but also increase the number of replicas deployed on a single node in an ACK cluster and reduce the resource costs of replicas in a Serverless Kubernetes cluster. This topic describes how to enable the dynamic heap memory optimization feature.
Usage notes
The following table describes the usage notes that you must take note of before you enable the dynamic heap memory optimization feature.
Item | Recommended value | Usage note |
JDK version | Supported JDK version: Dragonwell_11_ElasticHeap | If you use a JDK version other than Dragonwell_11_ElasticHeap when you create an application, you cannot enable the dynamic heap memory optimization feature. If you change Dragonwell_11_ElasticHeap to another JDK version after you create an application, the dynamic heap memory optimization feature is automatically disabled. |
GC policy | Supported GC policy: G1 | If you use a GC policy other than G1 when you create an application, you cannot enable the dynamic heap memory optimization feature. If you change G1 to another GC policy after you create an application, the dynamic heap memory optimization feature is automatically disabled. |
JVM monitoring | ARMS | If you do not enable Application Real-Time Monitoring Service (ARMS), metrics such as Heap Memory Usage and JVM Memory Usage Trend are unavailable, but the dynamic heap memory optimization feature is not affected. |
Pods monitoring | Managed Service for Prometheus | If you do not enable Managed Service for Prometheus (Prometheus), metrics such as Heap Memory Usage and JVM Memory Usage Trend are unavailable, but the dynamic heap memory optimization feature is not affected. |
Maximum heap memory | The configured maximum available heap memory | If you do not configure the maximum available memory (Xmx), you cannot enable the dynamic heap memory optimization feature. |
Initial heap memory | Less than the maximum available heap memory | If the initial heap memory is no less than the maximum available heap memory, Enterprise Distributed Application Service (EDAS) optimizes the initial heap memory (Xms) based on specific algorithms. For more information, see Optimize default parameters. |
Enable dynamic heap memory optimization when you create an application
Log on to the EDAS console.
In the left-side navigation pane, choose . In the top navigation bar, select a region. In the upper part of the Applications page, select a microservices namespace from the Microservices Namespace drop-down list. Then, click Create Application in the upper-left corner of the Applications page.
In the Basic Information step of the Create Application wizard, configure the Cluster Type and Application Runtime Environment parameters.
Parameter
Description
Cluster Type
Select Kubernetes Clusters.
Application Runtime Environment
Select Java. In the Select Application section, select a deployment method.
Java: Select this option if you want to use a universal JAR package to deploy the application as a Dubbo or a Spring Boot application. You can reconfigure the Java Environment parameter after you select this option.
Tomcat: Select this option if you want to use a universal WAR package to deploy a Dubbo or a Spring application. You can reconfigure the Java Environment and Container Version parameters after you select this option.
Java Environment
Select the following Java environment:
Dragonwell_11_ElasticHeap
In the Monitoring and Governance Solution section, select Integrated Solution (Default) and click Next in the lower part of the page.
In the Configurations step of the Create Application wizard, configure the environment information, basic information, deployment mode, and resource parameters of the application, and click Next.
In the Advanced Settings step of the Create Application wizard, click Edit next to the Settings of Java Startup Parameters parameter. In the Edit Java Startup Parameters dialog box, configure the Initial Heap Size and Maximum Heap Memory parameters, set the Young Generation GC Policy and Old Generation GC Policy parameters to G1, and then click OK.
Click the Dynamic Heap Memory Optimization parameter and turn on or off Whether to Enable Dynamic Heap Memory Optimization.
Enable dynamic heap memory optimization when you update an application
Log on to the EDAS console.
In the left-side navigation pane, click . In the top navigation bar, select a region. In the upper part of the page, select a namespace. Select Container Service or Serverless Kubernetes Cluster from the Cluster Type drop-down list. Then, find the application that you want to deploy and click the application name.
On the Overview or Basic information page, choose in the upper-right corner.
On the Select Deployment Mode page, select a deployment mode and click Start Deployment in the upper-right corner of the specified deployment mode section.
On the application deployment settings page, configure the Application Runtime Environment parameter, set the Java Environment parameter to Dragonwell_11_ElasticHeap, and then configure the deployment package information. Click Edit next to the Settings of Java Startup Parameters parameter. In the Edit Java Startup Parameters dialog box, configure the Initial Heap Size and Maximum Heap Memory parameters, set the Young Generation GC Policy and Old Generation GC Policy parameters to G1, and then click OK.
Click the Dynamic Heap Memory Optimization parameter to view the details of dynamic memory optimization.
Metrics and charts for dynamic heap memory optimization
Metrics
When the dynamic heap memory optimization feature is enabled, EDAS calculates the current memory usage-related metrics based on the memory usage of the application in the last 15 minutes. Formula:
Heap memory usage in the last 15 minutes = Average used heap memory size in the last 15 minutes/Average used pod memory size in the last 15 minutes
Average used heap memory size in the last 15 minutes = Avg (Used JVM heap size in the last 15 minutes, one data point per minute).
Average used pod memory size in the last 15 minutes = Avg (Maximum used memory size of the application pod in the last 15 minutes). The step size is one minute.
Charts
Charts for dynamic heap memory optimization display the memory settings of applications and the memory change curves in the last seven days to help you observe the heap memory changes between with and without the dynamic heap memory optimization feature. The charts show data of the following metrics:
Pod Memory Usage: the memory data of the pod in the last seven days, one data point per day. Data source: Prometheus.
JVM Heap: the heap memory of the application in the last seven days, one data point per day. Data source: ARMS.
JVM Old Generation: the data of the old generation in the last seven days, one data point per day. Data source: ARMS.
Dynamically adjust heap memory optimization parameters
Optimize default parameters
If you configure only Xmx for an application, EDAS automatically sets Xms to 128 MB after you enable the heap memory optimization feature for the application.
If you configure only Xmx for an application and the Xmx value equals the Xms value, EDAS sets Xms to 128 MB after you enable the dynamic heap memory optimization feature.
After you enable the dynamic heap memory optimization feature, EDAS adds parameter -XX:G1PeriodicGCInterval and sets the value of the parameter to 60000 for the application that uses G1 as the GC policy to adjust the Java virtual machine (JVM) collection policy.
Optimize custom parameters
After you enable the dynamic heap memory optimization feature for an application, EDAS returns part of the memory for the application to the OS. The returned memory can be used by other processes. If you want to reserve more memory for the application during the usage process, you can configure the parameters that are described in the following table to make improvement.
Parameter | Description | References |
MaxHeapFreeRatio | You can configure MaxHeapFreeRatio to control the maximum ratio of allowed idle heap memory. In HotSpot JDK V8, V11, and V17, the default value of MaxHeapFreeRatio is 70%. For more information, visit Java Documentation. | For information about how to configure custom Java startup parameters, see Configure Java startup parameters. Example: -XX:MaxHeapFreeRatio = 80% |
MinHeapFreeRatio | You can configure MinHeapFreeRatio to control the minimum ratio of allowed idle heap memory. In HotSpot JDK V8, V11, and V 17, the default value of MinHeapFreeRatio is 40%. For more information, see Java Documentation. | For information about how to configure custom Java startup parameters, see Configure Java startup parameters. Example:-XX:MaxHeapFreeRatio = 50% |
View execution results
Method 1: On the Change List page of an application, view the change details of the application. If Success is displayed in the Execution status field, the application is deployed and the dynamic heap memory optimization feature takes effect.
Method 2: On the Application Overview page of an application, click the pod status link next to the Running Status parameter. In the Pod section, check the Status of the desired pod. If a green round icon that indicates the pod is running appears, the application is deployed and the dynamic heap memory optimization feature takes effect.