Some Alibaba Cloud Elasticsearch (ES) instances support garbage collector configuration. For instances with large heap memory, switching from the default Concurrent Mark Sweep (CMS) garbage collector to G1 reduces garbage collection pause frequency and duration, improving cluster stability and query performance.
Background
ES versions earlier than 8.x use CMS by default. CMS triggers a collection cycle when heap memory usage reaches 75%. On instances with large heap memory, this threshold is hit frequently, causing longer and more disruptive pauses. G1 handles large heaps more efficiently.
ES 8.x and later use G1 by default, and the garbage collector cannot be changed.
Prerequisites
Before you begin, make sure your instance meets both of the following requirements:
Version: 6.7.0 to 8.x (earlier than 8.x)
Data node memory: 32 GB or more (total memory = single node memory x number of data nodes)
To check total data node memory:
Go to the Basic Information page of the target instance.
In the Node Visualization section, find the data node specifications.
Calculate: total memory = single node memory x number of data nodes.
If the memory requirement is not met, upgrade the instance first. For details, see Upgrade a cluster.
Rolling restart impact
Switching the garbage collector triggers a rolling restart of the cluster. During a rolling restart, nodes restart one at a time, so the cluster continues to serve requests but may experience brief response delays.
Restart duration depends on cluster size and data volume:
| Cluster size | Expected duration |
|---|---|
| Small | 10–30 minutes |
| Large | 30–60 minutes |
When the cluster can continue serving traffic without interruption:
The cluster can generally handle a rolling restart without service interruption if:
Replica shards are present on cluster indexes
CPU usage is around 60%
Heap memory usage is around 50%
load_1mis below the number of CPU cores
When brief access timeouts may occur:
If the cluster load is high, indexes have no replica shards, or there are heavy write or query operations, configure a retry mechanism in your client before proceeding.
Perform this operation during off-peak hours.
Switch to G1
Log on to the Alibaba Cloud Elasticsearch console.
In the left navigation pane, click Elasticsearch Clusters.
In the top menu bar, select the resource group and region. Then, in the Elasticsearch Clusters list, click the target instance ID.
In the left navigation pane, choose Configuration and Management > Cluster Configuration.
In the Basic Configuration section, click Modify to the right of Garbage Collector.
If the Modify button is grayed out, the instance does not meet the prerequisites: the data node memory is less than 32 GB, or the version is outside the supported range. Upgrade the instance or verify version compatibility before proceeding.
On the Modify Configuration page, select G1 and click OK. The cluster automatically restarts. After the restart completes, the switch to G1 takes effect.
API reference
To switch the garbage collector programmatically, use the UpdateAdvancedSetting API.