sequence
This article will focus on the new JDK support for Docker containers
Java8 and java9
Java 8U131 and above supports CPU and memory limits for Docker.
cpu limit
That is, if no explicit -xx :ParalllelGCThreads or -xx :CICompilerCount is specified, then the JVM uses the DOCker CPU limit. If the DOCker specified CPU limit and the JVM parameter specified -xx :ParalllelGCThreads or -xx :CICompilerCount, then the specified parameter will be used.
memory limit
In java8u131 + and java9, need to add – XX: XX: + UnlockExperimentalVMOptions – + UseCGroupMemoryLimitForHeap can make -xmx perception docker memory limit.
View the parameter defaults
java -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal
Copy the code
Part of the output
bool UseCGroupMemoryLimitForHeap = false {experimental} {default}
Copy the code
Can see in java9 UseCGroupMemoryLimitForHeap or experimental parameters, off by default.
java10
bool UseCGroupMemoryLimitForHeap = false {experimental} {default}
Copy the code
Java10 UseCGroupMemoryLimitForHeap still experimental, but marked as obsolete.
However, java10 introduces a new parameter
int ActiveProcessorCount = -1 {product} {default}
Copy the code
ActiveProcessorCount can be used to specify the number of cpus
java11
Java11 officially removed UseCGroupMemoryLimitForHeap, code changes to see 8194086: Remove deprecated experimental flag UseCGroupMemoryLimitForHeap
A new parameter is also introduced
bool UseContainerSupport = true {product} {default}
Copy the code
UseContainerSupport is true by default. You can use the -xlog: OS +container=trace argument to view details. The value of -xx :ActiveProcessorCount is used if specified, even if container support is disabled with -xx: -usecontainerSupport.
summary
Parameter/Version | -XX:+UseCGroupMemoryLimitForHeap | -XX:ActiveProcessorCount | -XX:+UseContainerSupport |
---|---|---|---|
java9 | Experimental, false by default | There is no | There is no |
java10 | Experimental, false by default | – 1 | There is no |
java11 | remove | – 1 | Product, default true |
doc
- Java SE support for Docker CPU and memory limits
- Docker CPU limits
- Experimental support for Docker memory limits
- Docker memory limits
- What to Expect from Java 10 — One Developer’s View
- Remove deprecated experimental flag UseCGroupMemoryLimitForHeap
- 8194086: Remove deprecated experimental flag UseCGroupMemoryLimitForHeap
- Improve docker container detection and resource configuration usage