libraries decide how much memory and how many threads to use. This decision is based on a host hardware configuration. JVM and many libraries are designed to take a full advantage of all available resources. • JVM ergonomics • Libraries ergonomics These ergonomics work well in VM but not in a container
and cgroups • In a docker instance, an application can access a host hardware configuration • Java doesn't know about Docker and cgroups (before April 2017) • Java reads host configuration from /proc not from /sys/fs/cgroup • Demo (htop shows java process)
without heap limit (no -Xmx option) • I hope nobody does this in production. But it works well in some circumstances. • According to current server JVM ergonomic, JVM will take ¼ of RAM for a heap
tell JVM (8u131+) how many real cores you allow to use But this approach is very bad for resource utilization. It’s better • Use --cpus or --cpu-shares and don’t deploy CPU heavy services on the same host. • Configure JVM and an application according to provisioned resources
-XX:MaxRAM=n Sets the maximum amount of memory used by the JVM -XX:+UseCGroupMemoryLimitForHeap This flag present in the more recent builds of JDK8 tells the JVM to use the information in /sys/fs/cgroup/memory/memory.limit_in_bytes to calculate memory defaults. -XX:ParallelGCThreads=n Set the number of parallel GC threads to n. This is helpful if you are trying to limit the cpu usage of your container.