background
Java startup normally queries the operating system in order to setup runtime defaults for things such as the number of GC threads and default memory limits.
While in docker container, JVM can’t get the resource limit info.
This problem had been fixed in JDK8:8u191
This article make a test for the new feature
VM info
a linux vm in google cloud, with 6 vCPUS, 20GB memory
Test In VM
1 | bamboo@privacy:~$ free -g |
Test in docker container (openjdk:8u181) without resource limit
1 | bamboo@privacy:~$ docker run -ti openjdk:8u181-jdk |
Test in docker container (openjdk:8u181) with resource limit
8G memory, 2 cpus
1 | bamboo@privacy:~$ docker run -it --cpus 2 -m 8g openjdk:8u181-jdk bash |
Test in docker container (openjdk:8u212) without resource limit
1 | bamboo@privacy:~$ docker run -ti openjdk:8u212-jdk |
Test in docker container (openjdk:8u212) with resource limit
8G memory, 2 cpus
1 | bamboo@privacy:~$ docker run -it --cpus 2 -m 8g openjdk:8u212-jdk bash |
compare table
env\command | free -g | cat /proc/cpuinfo | jvm InitialHeapSize | jvm MaxHeapSize | jvm ParallelGCThreads |
---|---|---|---|---|---|
VM | 20G | 6 | 329252864 (314M) | 5263851520 (4.9G) | 6 |
docker (openjdk:8u181) | 20G | 6 | 329252864 | 5263851520 | 6 |
docker (openjdk:8u181) resource limit [cpu:2, memory:8G] | 20G | 6 | 329252864 | 5263851520 | 6 |
docker (openjdk:8u212) | 20G | 6 | 329252864 | 5263851520 | 6 |
docker (openjdk:8u181) resource limit [cpu:2, memory:8G] | 20G | 6 | 134217728 (128M) | 2147483648 (2G) | 2 |
conclusion
- openjdk:8u212 can get the resource limit in docker container
implementation
1 | julong os::Linux::available_memory() { |
link
JDK-8146115 : Improve docker container detection and resource configuration usage
jira : https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8146115
patch : http://cr.openjdk.java.net/~bobv/8146115/webrev.03/open.patch