You can configure the garbage collection mechanism of Java Virtual Machine (JVM) and Just-In-Time (JIT) parameters to better make use of the in-place scaling feature of ACS during the startup of Java applications. This topic provides suggested JVM settings to accelerate the startup of Java applications, including the ParallelGCThreads, ConcGCThreads, and CICompilerCount parameters.
Background information
During the startup of a Java application, it needs to load classes, compile bytecodes, and optimize bytecodes, which are complex. The startup process may require even tens of minutes. The Java application usually occupies more than half of the resources during its startup to load and compile non-application code. After the application runs stably, these resources become idle. You can use the in-place scaling feature of ACS to allocate more compute power during the startup of a Java application to accelerate it.
Compiling threads, user threads, and garbage collection threads are running on JVMs. The proportion of resources occupied by these threads varies based on the operation stage of the Java application. To better accelerate the startup of Java applications and ensure that they can run stably, you can modify the JVM parameters to allocate resources to these threads properly.

Suggested JVM configuration
The following section describes the parameters that are related to Java application startups and their suggested settings, including ParallelGCThreads, ConcGCThreads, and CICompilerCount.
Assume that the number of vCPUs allocated to the user application is
JVM parameter | Description | Suggested setting | |
| The number of parallel garbage collection threads. | If If | |
| The number of concurrent garbage collection threads. These threads run concurrently with the application thread to reduce the downtime. Therefore, you need to reserve sufficient CPU resources for these threads. | Set | |
| The number of JIT compiling threads. The value affected the application efficiency. Frequent JIT compiling may cause a performance bottleneck. If the number of JIT threads is too small, the method execution efficiency may be compromised and excessive CPU resources may be occupied. | vCPUs ( |
|
1 | 2 | ||
2 | 2 | ||
4 | 3 | ||
8 | 3 | ||
16 | 8 | ||
32 | 10 | ||
64 | 12 | ||
Use scenarios
Orchestration configuration
When the system creates an instance for a Java application, you can use in-place scaling to double the CPU resources allocated to the application and ensure that the scaling lasts only the application enters the Ready state. This can efficiently accelerate the startup of the application. If the application needs to load too many libraries or it needs to perform other initialization operations in addition to JVM compiling and warmup, the scaling can last longer.
If the application performs the warmup after scale-down, garbage collection and JIT threads may compete with the application for CPU resources when the CPU usage is high. This is because the garbage collection and JIT threads are allocated more vCPUs during the scale-up. To resolve this issue, make sure that your application completes the warmup during the scale-up.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: spring-with-burst
name: spring-with-burst
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: spring-with-burst
minReadySeconds: 400 # Set a value that is greater than one during the CPU Burst duration. This way, you can verify the status of the instance after the CPU Burst ends.
template:
metadata:
annotations:
alibabacloud.com/startup-cpu-burst-factor: '2' #Set the CPU Burst factor to 2. The original 1 vCPU is scaled to 2 vCPUs during the startup.
alibabacloud.com/startup-cpu-burst-duration-seconds: "300" #The default value (30 seconds) is too short. Most Java applications need 10 minutes or less to start up and another 5 minutes to complete the warmup. We recommend that you set a larger value.
scaling.alibabacloud.com/enable-inplace-resource-resize: 'true' # Enable in-pace scaling.
labels:
alibabacloud.com/compute-class: general-purpose
alibabacloud.com/compute-qos: default
app: spring-with-burst
spec:
containers:
- image: 'registry.cn-hangzhou.aliyuncs.com/acs-demo-ns/demo-java:java-with-metrics-v1'
imagePullPolicy: IfNotPresent
name: spring
ports:
- containerPort: 8080
protocol: TCP
resources:
limits:
cpu: 1
memory: 4Gi
requests:
cpu: 1
memory: 4GiJVM configuration
To double the number of vCPUs, you can use the following configuration.
Original vCPUs | vCPUs after CPU Burst | ParallelGCThreads | ConcGCThreads | CICompilerCount |
0.5 | 1 | 1 | 1 | 2 |
1 | 2 | 2 | 1 | 2 |
2 | 4 | 4 | 1 | 3 |
4 | 8 | 8 | 2 | 3 |
8 | 16 | 13 | 3 | 8 |
You can run the following Java command in the container to check the default thread configuration used by the current Java version, such as ParallelGCThreads:
java -XX:+PrintFlagsFinal -version | grep ParallelGCThreadsFor example, the original 1 vCPU is scaled to 2 vCPUs. If the default thread configuration greatly differs from the suggested setting, you can modify the boot command of the Java application as follows:
java -XX:ParallelGCThreads=2 -XX:ConcGCThreads=1 -XX:CICompilerCount=2 -jar app.jar