ParallelGCThreads default value is not correct in OpenShift
Environment
- OpenJDK 8, OpenJDK 11, OpenJDK 17
- Red hat OpenShift Container Platform (OCP)
- 4.x
Issue
Usage of Parallel GC for an java container returns different ParallelGCThreads than VM usage.
Resolution
Given a container aware JDK, like OpenJDK 8u191+, the JVM detects the cpus and memory settings at start-up from the cgroups values - meaning from the CPU resource limits.
In some specific cases, when the default number of threads is not adequate, the user can specific a fixed number for ParallelGCThreads for the Java application in the container/pod on the deployment/deployment container by overwriting ParallelGCThreads/Concurrent JVM via JVM flag. However, this value should be calculated according to workload and tested against the default values.
Root Cause
As explained on the solution Should -XX:+UseContainerSupport flag be used in OpenJDK images?, recent versions of the JDK are container aware and it will deduce the number of CPUs running from the cgroups.
ParallelGCThreads are calculated based on the JDK algorithm (so gc specific) and calculated from the number of cpus used on the settings - for OCP deployed via deployment/deploymentconfig, the number of cpus are set via limit/requests.
From the cpus the calculation is according to the gc collector. For calculation of ParallelGCThreads see Tuning ParallelGCThreads / ConcGCThreads in CMS on OpenJDK and How G1GC calculates the default value for ConcGCThreads and ParallelGCThreads.
GC collector | ParallelGCThreads/Concurrent threads calculation |
---|---|
CMS | ParallelGCThreads calculation |
G1GC | ConcGCThreads and ParallelGCThreads calculation |
Shenandoah | ConcGCThreads and ParallelGCThreads calculation |
Diagnostic Steps
# java -version | grep GCThreads
Picked up JAVA_TOOL_OPTIONS: -XX:+UseParallelGC -XX:+PrintFlagsFinal
uintx ConcGCThreads = 0 {product}
uintx HeapSizePerGCThread = 87241520 {product}
uintx ParallelGCThreads = 4 {product}
bool TraceDynamicGCThreads = false {product}
bool UseDynamicNumberOfGCThreads = false {product}
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.