Non-fixed value configuration of JVM parameters in Docker environment - the road to dream building

1. Print java process information from the command line

jinfo -flags 1

从进程信息中可以看到Xms和Xmx 的值

默认是Xms是16777216,即16M。Xmx是262144000,即256M

There was a saying before that in the container environment, because java cannot obtain the memory limit of the container, it can only obtain the configuration of the server.

This was indeed the case before, but in order to better use the container environment, Java introduced + UseContainerSupport(enabled by default) in Java 10. Through this feature, the JVM can allocate reasonable heap memory in the container environment.

Later, this feature was also integrated into the JDK8U191 version. Java8 after the JDK8U191 version can also obtain the memory limit of the container.

2. UseContainerSupport

-XX:+UseContainerSupport允许JVM 从主机读取cgroup限制,例如可用的CPU和RAM,并进行相应的配置。这样当容器超过内存限制时,会抛出OOM异常,而不是杀死容器。 该特性在Java 8u191 +,10及更高版本上可用。

注意,在191版本后,-XX:MinMaxRAMFraction 被弃用,引入了-XX:MaxRAMPercentage,其值介于0.0到100.0之间,默认值为25.0。

3. Best Practices

在应用的启动参数,设置 -XX:+UseContainerSupport,设置-XX:MaxRAMPercentage=75.0,这样为其他进程(debug、监控)留下足够的内存空间,又不会太浪费RAM。

Guess you like

Origin blog.csdn.net/qq_34777982/article/details/130948538