-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add notes about CPU and RAM limits #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
openjdk/content.md
Outdated
|
||
## Make JVM respect CPU and RAM limits | ||
|
||
On starup JVM tries to detect the number of available CPU cores and the amount of RAM to adjust its internal parameters (like the number of garbage collector threads to spawn) accordingly. When container is run with limited CPU/RAM, standard system API, used by JVM for probing, will return host-wide values. This can cause excessive CPU usage and memory allocation errors with older versions of JVM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/starup/startup
.
@TimWolla , thanks for the correction! Fixed. |
|
||
On startup JVM tries to detect the number of available CPU cores and the amount of RAM to adjust its internal parameters (like the number of garbage collector threads to spawn) accordingly. When container is run with limited CPU/RAM, standard system API, used by JVM for probing, will return host-wide values. This can cause excessive CPU usage and memory allocation errors with older versions of JVM. | ||
|
||
Inside Linux containers, recent versions of OpenJDK 8 can correctly detect container-limited number of CPU cores by default. To enable the detection of container-limited amount of RAM the following options can be used: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the version we have actually include this new functionality? (I thought we were still a release or two behind due to Debian's backport process? 8u121 in jessie-backports
vs 8u131 in stretch
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not yet, openjdk:8-jdk is at 1.8.0_121
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenJDK 9 too? (>=b150 afaict)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, it looks like all docker-library jdks 8 are now at least on 8u131 that has cgroups flag, is it possible to have this doc change merged?
$ start /b /wait /affinity 0x3 path/to/java.exe ... | ||
``` | ||
|
||
In this example CPU affinity hex mask `0x3` will limit JVM to 2 CPU cores. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this limit to 2 CPU cores generally, or does this limit to 2 specific cores? (ie, docker run --cpuset-cpus
vs docker run --cpus
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mask 0x3 - 0011
limits CPU to 2 specific cores - core0 and core1, its a windows feature, not jdk-specific.
|
||
In this example CPU affinity hex mask `0x3` will limit JVM to 2 CPU cores. | ||
|
||
RAM limit is supported by Windows Server containers, but currently JVM cannot detect it. To prevent excessive memory allocations, `-XX:MaxRAM=...` option must be specified with the value that is not bigger than a containers RAM limit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, nice -- I had no idea there was a JVM parameter for controlling MaxRAM
rather than trying to set -Xmx
and friends intelligently! (related to docker-library/openjdk#57 and docker-library/openjdk#71)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, MaxRAM
may be more convenient. This one-liner can be used to check what Xmx
(max heap) value will be used when MaxRAM
is specified:
jrunscript -J-XX:MaxRAM=256M -e "print(Packages.java.lang.Runtime.getRuntime().maxMemory()/(1<<20) + 'M')"
Thanks @akashche! |
@akashche Thank you for this!!! |
Relevant links:
https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/
https://bugs.openjdk.java.net/browse/JDK-6515172
https://bugs.openjdk.java.net/browse/JDK-8170888
https://bugs.openjdk.java.net/browse/JDK-8157478
moby/moby#27892
moby/moby#30594
https://superuser.com/a/908870
https://technet.microsoft.com/en-us/library/cc770297%28v=ws.11%29.aspx