做java标志Xms和Xmx覆盖标志XX:+ UseCGroupMemoryLimitForHeap? [英] Do java flags Xms and Xmx overwrite flag XX:+UseCGroupMemoryLimitForHeap?

查看:1716
本文介绍了做java标志Xms和Xmx覆盖标志XX:+ UseCGroupMemoryLimitForHeap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Kubernetes中运行一个容器化的java应用程序。

I'm running a containerized java application in Kubernetes.

为了根据容器规范生成jvm预留内存,标志 -XX:+ UnlockExperimentalVMOptions -XX:+ UseCGroupMemoryLimitForHeap 必须设置。

In order to make the jvm reserve memory according to the container specifications, the flags -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap must be set.

如果这两个标志都与Xms和Xmx标志一起设置, jvm的行为是什么?一面旗帜会覆盖另一面吗?

If both those flags are set along with Xms and Xmx flags, what would the behavior of the jvm be? Do one flag overwrite the other?

例如,如果我们有 java -XX:+ UnlockExperimentalVMOptions -XX:+ UseCGroupMemoryLimitForHeap -Xms -Xms2500M -Xmx2500M -jar myjar.jar
在容器限制为4Gi的容器中,4Gi用于响应,在具有128Gi内存的主机中,JVM预留多少内存?

For example, if we had java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms -Xms2500M -Xmx2500M -jar myjar.jar in a pod with container limits 4Gi for requests and 4Gi for responses, in a host machine that has 128Gi memory, how much memory would the JVM reserve?

推荐答案

-Xmx标志覆盖-XX:+ UseCGroupMemoryLimitForHeap标志。

The -Xmx flag overwrites the -XX:+UseCGroupMemoryLimitForHeap flag.

标志-XX:+ UseCGroupMemoryLimitForHeap允许JVM检测容器中的最大堆大小应该是什么。

The flag -XX:+UseCGroupMemoryLimitForHeap lets the JVM detect what the max heap size in a container should be.

-Xmx标志将最大堆大小设置为固定大小。

The -Xmx flag set the max heap size to a fixed size.

为了回答你的例子,JVM将保留2500M的堆空间。非堆和jvm的内存会有一些额外的内存使用。

To answer your example, the JVM would reserve 2500M heap space. There will be some additional memory usage for non-heap and jvm stuff.

要进一步调整容器中的内存使用量,可以使用-XX:MaxRAMFraction标志。
参见此文章: https://blog.csanchez.org/2017/05/31/running-a-jvm-in-a-container-without-getting-killed/

To further tune your memory usage in a container you could use the -XX:MaxRAMFraction flag. See this article: https://blog.csanchez.org/2017/05/31/running-a-jvm-in-a-container-without-getting-killed/

这篇关于做java标志Xms和Xmx覆盖标志XX:+ UseCGroupMemoryLimitForHeap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆