Reputation: 4901
We have a Java based micro-service application running in docker container. Since the services require different memory settings, we have to specify the memory limits of both the Docker container and the JVMs (-Xmx
).
I am aware of that Java has container support from Java 10, but that means only certain options takes the resource limits of the container into consideration.
My question is there any setting that makes the JVM fully utilize the available memory of the container? For example, if the container has 1GB, then the JVM utilizes this by sharing this memory among its heap and non-heap memory(stack, classes etc.) optimally.
Upvotes: 1
Views: 1196
Reputation: 44980
There is no magic flag that will size the Java memory for you. A workload of one micro-servies might be different from another and will require different memory configuration.
You would have to manually set the -Xms
, -Xmx
, and other parameters. If they are not set the JVM will use defaults e.g. -Xmx
will be defaulted to 25% of available RAM.
Java 8 and 9 have +XX:+UseContainerSupport
only but since Java 10 this is now the default behavior. This option makes the JVM respect the resource limits imposed by the container but doesn't automatically scale the memory.
Upvotes: 1