From dde2e3ffbb4f2b60497e3f9490594afdaaec3b1a Mon Sep 17 00:00:00 2001 From: Docker Library Bot Date: Thu, 3 Aug 2017 18:32:28 +0000 Subject: [PATCH] Run update.sh --- hello-world/README.md | 2 +- hello-world/content.md | 2 +- openjdk/README.md | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hello-world/README.md b/hello-world/README.md index 40450fa35..93421e4af 100644 --- a/hello-world/README.md +++ b/hello-world/README.md @@ -72,7 +72,7 @@ For more examples and ideas, visit: $ docker images hello-world REPOSITORY TAG IMAGE ID SIZE -hello-world latest 1815c82652c0 1.84kB +hello-world latest 1815c82652c0 1.84 kB ``` ![logo](https://raw.githubusercontent.com/docker-library/docs/01c12653951b2fe592c1f93a13b4e289ada0e3a1/hello-world/logo.png) diff --git a/hello-world/content.md b/hello-world/content.md index 804460cbe..b7a7eb18b 100644 --- a/hello-world/content.md +++ b/hello-world/content.md @@ -26,7 +26,7 @@ For more examples and ideas, visit: $ docker images hello-world REPOSITORY TAG IMAGE ID SIZE -hello-world latest 1815c82652c0 1.84kB +hello-world latest 1815c82652c0 1.84 kB ``` %%LOGO%% diff --git a/openjdk/README.md b/openjdk/README.md index 1b7f32067..cb7402d9a 100644 --- a/openjdk/README.md +++ b/openjdk/README.md @@ -107,6 +107,26 @@ $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp openjdk:7 javac Mai 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 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: + +```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. + # Image Variants The `openjdk` images come in many flavors, each designed for a specific use case.