Navigate back to the homepage

Running a JVM inside a container

Nancy Chauhan
December 26th, 2018 · 1 min read

Many applications that run in a Java Virtual Machine (JVM),are run in containers. But running the JVM in a container presented problems with memory and cpu sizing and usage that led to performance loss. It might kill the other images

This happened because Java didn’t recognize that it was running in a container . Containers are made possible by using Kernal features of the operating system, one of which is called cgroups, which isolates the resource usage (CPU, memory, disk I/O) of the containers.

But not all things know about cgroups, which can lead to strange results

But Both memory and cpu constraints can be used manage Java applications directly in containers, these include:

1adhering to memory limits set in the container
2setting available cpus in the container
3setting cpu constraints in the container

The JVM, prior to JDK10, is unaware of cgroups. So ergonomic calculations are not based on the limits for the container

To fix this we need to set the JVM max heap size, but I’m still not inclined to want to explicitly set these. Ideally, the JVM would still provide sensible defaults. And as it turns out the JVM has some additional flags which allow it to do this.

1-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap

A very good Reference : https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/

More articles from Nancy Chauhan

Linux chmod Command

chmod is used to change the permissions of files or directories.

November 4th, 2018 · 1 min read

Lift As You Climb

“And so, lifting as we climb, onward and upward we go, struggling and striving, and hoping that the buds and blossoms of our desires will burst into glorious fruition ere long.”

October 17th, 2018 · 2 min read
© 2018–2022 Nancy Chauhan
Link to $https://twitter.com/_nancychauhanLink to $https://github.com/Nancy-ChauhanLink to $https://www.linkedin.com/in/nancy-chauhan/Link to $https://www.instagram.com/heyanancy/Link to $https://medium.com/@_nancychauhan