Before we dig in...
Setting memory and CPU constraints to containers is very popular technique especially for public cloud offerings (such as OpenShift). Behind the scenes everything works based on adding additional Docker settings to the containers. There are two very popular switches: --memory (which is responsible for setting the amount of available memory) and --cpu-quota (which throttles CPU usage).
Now here comes the best part... JDK has no idea about those settings! We will probably need to wait until JDK9 for getting full CGroups support.
What can we do about it?
The answer is very simple, we need to tell JDK what is the available memory (at least by setting Xmx) and available number of CPUs (by setting XX:ParallelGCThreads, XX:ConcGCThreads and Djava.util.concurrent.ForkJoinPool.common.parallelism).
And we have some very good news! We already did it for you!
Let's test it out!
At first you need to pull our latest Docker image:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker pull jboss/infinispan-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker run -m 500M --cpu-quota=600000 jboss/infinispan-server | |
JAVA_OPTS already set in environment; overriding default settings with values: -Xms64m -Djava.net.preferIPv4Stack=true -Xmx350m -XX:ParallelGCThreads=6 -XX:ConcGCThreads=6 -Djava.util.concurrent.ForkJoinPool.common.parallelism=6 | |
========================================================================= | |
JBoss Bootstrap Environment | |
JBOSS_HOME: /opt/jboss/infinispan-server | |
JAVA: /usr/lib/jvm/java/bin/java | |
JAVA_OPTS: -server -server -Xms64m -Djava.net.preferIPv4Stack=true -Xmx350m -XX:ParallelGCThreads=6 -XX:ConcGCThreads=6 -Djava.util.concurrent.ForkJoinPool.common.parallelism=6 | |
========================================================================= | |
09:28:45,027 INFO [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final | |
... |
- -Xms64m -Xmx350m - it is always a good idea to set Xmn inside a Docker container. Next we set Xmx to 70% of available memory.
- -XX:ParallelGCThreads=6 -XX:ConcGCThreads=6 -Djava.util.concurrent.ForkJoinPool.common.parallelism=6 - The next thing is setting CPU throttling as I explained above.
There might be some cases where you wouldn't like to set those properties automatically. In that case, just pass -n switch to the starter script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker run -m 500M --cpu-quota=600000 jboss/infinispan-server -n |
More reading
If this topic sounds interesting to you, do not forget to have a look at those links:
No comments:
Post a Comment