简体   繁体   English

Java 堆在 docker 容器内

[英]Java heap inside docker container

I ran this command which I found in this blog .我运行了这个我在这个博客中找到的命令。

docker run -m 1GB openjdk:10 java \
-XX:+UseContainerSupport \
-XX:MinRAMPercentage=50 \
-XX:MaxRAMPercentage=80 \
-XshowSettings:vm \
-version

My output is this.我的output是这个。

VM settings:
    Max. Heap Size (Estimated): 3.86G
    Using VM: OpenJDK 64-Bit Server VM

openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Debian-2)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Debian-2, mixed mode)

I am little bit confused now is that, when I limit the memory to 1G, why does Java see 3.86G or What needs to be done to make java see container memory limits?我现在有点困惑的是,当我将 memory 限制为 1G 时,为什么 Java 看到3.86G或者需要做什么才能使 java 看到容器 memory 限制?

Note: I am on MAC.注意:我在 MAC 上。 docker creates container inside the VM. docker 在 VM 中创建容器。 So not sure if it matters.所以不确定这是否重要。

When using Java in containers, one needs to be mindful of to what degree the JVM is aware of the resource limits set for the container it runs in. With Java version 10 (released in 2018) the JVM was first enabled to figure out whether it is running in a container, and if yes, how much memory was allocated to the container.在容器中使用 Java 时,需要注意 JVM 在多大程度上了解为其运行的容器设置的资源限制。使用 Java 版本 10(2018 年发布) ,首先启用 JVM 以确定它是否是运行在一个容器中,如果是的话,给容器分配了多少memory。 Back then, CGroups V1 was used by the Linux Kernel to curtail the memory available to containers.当时,CGroups V1 被 Linux Kernel 用来减少容器可用的 memory。

In the mean time, CGroups V2 (conceived in 2016) is gaining traction and is increasingly becoming the default for new Linux releases (eg Ubuntu and Flatcar Linux made it default in 2021).与此同时,CGroups V2(构思于 2016 年)越来越受欢迎,并越来越成为新 Linux 版本的默认设置(例如 Ubuntu 和 Flatcar Linux 使其在 2021 年成为默认设置)。 This means, once again a Java update is required to support CGroups V2 for correct handling of JVM resource limits and Heap configuration , which for OpenJDK came with Java version 15 .这意味着,再次需要 Java 更新来支持 CGroups V2 以正确处理 JVM 资源限制和堆配置,OpenJDK 附带Java 版本 15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM