A very important release announced in a post on the Oracle blog. Java SE support for Docker CPU and memory limits
In short: “As of Java SE 8u131, and in JDK 9, the JVM is Docker-aware with respect to Docker CPU limits transparently.”
SET 1:
If -XX:ParalllelGCThreads, or -XX:CICompilerCount are not specified as command line options, the JVM will apply the Docker CPU limit as the number of CPUs the JVM sees on the system. The JVM running inside the docker container will see the container (with its limits) as a bare-bone machine
SET 2:
If no -Xmx, or -Xms are not specified as command line options, there are two JVM command line options required, -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
So now setting up CPU and memory limits to a docker container in which a JVM is running makes more sense.
So now a version 3 docker-compose file of a jboss image having Java SE 8u131 from the original:
version '3'
services:
jboss:
build: ./app-server
deploy:
resources:
limits:
memory: 4G
cpu: 0.01
reservations:
memory: 2G
cpu: 0.005
environment:
- JAVA_OPTS=-Xmx4g -Xms2g -XX:ParalllelGCThreads=2 -XX:CICompilerCount=2
ports:
- "8080:8080"
- "8443:8443"
- "8787:8787"
- "9990:9990"
links:
- oracle:oracle
- activemq:activemq
stdin_open: true
tty: true
...
can be written with the new features in a shorter version and more clear:
version '3'
services:
jboss:
build: ./app-server
deploy:
resources:
limits:
memory: 4G
cpu: 0.01
reservations:
memory: 2G
cpu: 0.005
environment:
- JVM_OPTS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
ports:
- "8080:8080"
- "8443:8443"
- "8787:8787"
- "9990:9990"
links:
- oracle:oracle
- activemq:activemq
stdin_open: true
tty: true
...