容器环境中的 Java 大堆

容器环境中的 Java 大堆

我正在尝试在 kubernetes 上运行 Jetty 网络服务器,它需要大量的堆,在我们的生产环境中大约 250 GB,在我们的测试环境中大约 50 GB。

我正在使用jetty:9.4-jdk11,我试图避免明确设置XmsXmx标志,因为不同环境之间的值不同,因为我认为取决于-XX:MaxRAMPercentage -XX:InitialRAMPercentage会更好,但无论我尝试什么,我都无法MaxHeapSize超过 32178700288 ~ 30 GB。

该节点上只有 Java 应用程序和几个小 sidcar,拥有 64 GB 内存。

Dockerfile

FROM jetty:9.4-jdk11

ENV APP_WAR root.war
ENV APP_EXPLODED_WAR root/
ENV APP_DESTINATION_PATH $JETTY_BASE/webapps/
ENV APP_DESTINATION_WAR $APP_DESTINATION_PATH$APP_WAR
ENV APP_DESTINATION_EXPLODED_WAR $APP_DESTINATION_PATH$APP_EXPLODED_WAR

ADD . $APP_DESTINATION_EXPLODED_WAR

ENV JAVA_OPTIONS -XX:+PrintFlagsFinal -XX:MaxRAMPercentage=90 -XX:InitialRAMPercentage=90 -XX:-OmitStackTraceInFastThrow -XX:+UseStringDeduplication -Xlog:gc*,stringdedup*=debug:file=/tmp/gc.log:time

容器资源设置

resources:
  limits:
    cpu: "8"
    memory: 60G
  requests:
    cpu: "6"
    memory: 60G

根据这些值,我应该得到 60 GB MaxHeapSize~ 54 GB 的 90%,而不是 30 GB。知道我遗漏了什么吗?

答案1

-XX:+UseCompressedOopsJava 11 中默认启用的JVM 参数是导致此问题的原因,文档

-XX:-UseCompressedOops
    
Disables the use of compressed pointers. By default, this option is enabled, and compressed pointers are used when Java heap sizes are less than 32 GB. When this option is enabled, object references are represented as 32-bit offsets instead of 64-bit pointers, which typically increases performance when running the application with Java heap sizes of less than 32 GB. This option works only for 64-bit JVMs.
    
It’s also possible to use compressed pointers when Java heap sizes are greater than 32 GB. See the -XX:ObjectAlignmentInBytes option.

只需更改-XX:+-XX:-如上所示即可禁用它。

就我而言,不建议使用-XX:ObjectAlignmentInBytes,同样文档

-XX:ObjectAlignmentInBytes=alignment

Sets the memory alignment of Java objects (in bytes). By default, the value is set to 8 bytes. The specified value should be a power of 2, and must be within the range of 8 and 256 (inclusive). This option makes it possible to use compressed pointers with large Java heap sizes.

The heap size limit in bytes is calculated as:

4GB * ObjectAlignmentInBytes

Note:

As the alignment value increases, the unused space between objects also increases. As a result, you may not realize any benefits from using compressed pointers with large Java heap sizes.

但我想它值得测试。

相关内容