In version 8u131, the JVM became container aware. That means basically two things:
- The JVM will set its max heap space based on the cgroup's memory limit, taking most of that limit for the heap.
- The JVM will set its number of available processors based on the cgroup's settings for
cpu_shares
and/orcpu_quota
depending on the JVM version.
The first point (memory) is somewhat useful, it provides a more reasonable default for max heap space when the JVM is run in a container. Heap space can still be set directly via the -Xmx
and/or -Xms
flags, and probably should be most of the time.
The second point is somewhat less helpful, and potentially quite harmful, especially in Kubernetes. Kubernetes' pods resource CPU request and limit values control the cpu_shares
and cpu_quota
respectively (see https://christopher-batey.medium.com/cpu-considerations-for-java-applications-running-in-docker-and-kubernetes-7925865235b7 for more details). For now, it's enough to know that if