From 7ee2d9bdeddec51c6fe1528abf3aeeda08827ecc Mon Sep 17 00:00:00 2001 From: Alex Kashchenko Date: Sat, 6 May 2017 21:21:57 +0100 Subject: [PATCH 1/2] Add notes about CPU and RAM limits --- openjdk/content.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/openjdk/content.md b/openjdk/content.md index 59ef0323d..08a0d0ad7 100644 --- a/openjdk/content.md +++ b/openjdk/content.md @@ -38,3 +38,23 @@ $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp %%REPO%%:7 javac Ma ``` This will add your current directory as a volume to the container, set the working directory to the volume, and run the command `javac Main.java` which will tell Java to compile the code in `Main.java` and output the Java class file to `Main.class`. + +## 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. + +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: + +```console +$ java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap ... +``` + +Inside Windows Server (non-Hyper-V) containers, limit for number of available CPU cores does not work (is ignored by Host Compute Service). To set such limit manually, JVM can be started the following way: + +```console +$ start /b /wait /affinity 0x3 path/to/java.exe ... +``` + +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. From 4325be5ccb52721bfa26521beaee40e607c7b7af Mon Sep 17 00:00:00 2001 From: Alex Kashchenko Date: Sun, 7 May 2017 17:55:29 +0100 Subject: [PATCH 2/2] Typo fix in content.md --- openjdk/content.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openjdk/content.md b/openjdk/content.md index 08a0d0ad7..b641eebd2 100644 --- a/openjdk/content.md +++ b/openjdk/content.md @@ -41,7 +41,7 @@ This will add your current directory as a volume to the container, set the worki ## 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. +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: