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

查看:43
本文介绍了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 响应的 pod 中,在具有 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天全站免登陆