I'm getting warning "Container memory limit unset. Configuring JVM for 1G container." regardless RAM size or docker configuration

huangapple go评论84阅读模式
英文:

I'm getting warning "Container memory limit unset. Configuring JVM for 1G container." regardless RAM size or docker configuration

问题

我有一个 Spring Boot 应用,通过 mvn spring-boot:build-image 命令构建成 Docker 镜像。运行应用时会打印出一个警告消息:

警告:未设置容器内存限制。正在为 1G 容器配置 JVM。
计算得出的 JVM 内存配置:-XX:MaxDirectMemorySize=10M -Xmx192915K -XX:MaxMetaspaceSize=343660K -XX:ReservedCodeCacheSize=240M -Xss1M(总内存:1G,线程数:250,加载的类数:58260,头部空间:0%)

现在,不论在任何机器上运行,都会出现这个警告消息,无论是在我本地的 Windows Docker Desktop 上,还是在具有 2GB 或 4GB RAM 的 AWS 实例中。我对设置的最大堆大小为 200M 感到不满意...

这个内存计算中是否存在 bug,或者我是否可以进行一些调整?

更新:
我正在使用 Dockerrun.aws.json v1 来部署到 Beanstalk。所以我猜我无法控制 docker run 的参数。

英文:

I have a Spring Boot app which is built to a docker image by mvn spring-boot:build-image. When it runs it prints out a warning:

WARNING: Container memory limit unset. Configuring JVM for 1G container.
Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx192915K -XX:MaxMetaspaceSize=343660K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 1G, Thread Count: 250, Loaded Class Count: 58260, Headroom: 0%) 

Now this message seems to appear regardless a machine which it runs on. Whether it's on my local Docker Desktop on Windows or in AWS instance with 2 or 4 GB RAM. I'm not happy with the 200M set for maximum heap size...

Is there a bug in memory calculation or can I tweak it somehow?

UPDATE:
I'm using Dockerrun.aws.json v1 in order to deploy to Beanstalk. So I guess I have no control over docker run arguments.

答案1

得分: 1

通常情况下,您可以使用 docker run -m <size> 来设置内存限制。Java构建包和内存计算器将从 cgroup信息 中读取此值,然后根据您定义的内存限制调整JVM。

似乎在使用Amazon Elastic Beanstalk时,您可以在 Dockerrun.aws.json 中设置内存限制。请参阅他们的容器定义格式文档

有两个选项:

memory

容器实例上为容器保留的内存量。在容器定义中的memory或memoryReservation参数中的一个或两个参数中指定一个非零整数。

memoryReservation

为容器保留的内存软限制(以MiB为单位)。在容器定义中的memory或memoryReservation参数中的一个或两个参数中指定一个非零整数。

我不是Amazon Elastic Beanstalk的专家,但根据他们的文档,听起来您想要设置memory


如果由于某种原因无法设置内存限制,目前的唯一选择是忽略警告并使用默认的1G设置。

然后,您可能希望调整环境的大小,以免浪费资源。例如,如果您有一个4G的虚拟机,它只会配置JVM使用1G的内存,因此将虚拟机的大小调整为1G(或接近这个值),您将能够更好地利用可用的资源。

英文:

Normally, you'd set a memory limit with docker run -m &lt;size&gt;. The Java buildpack & memory calculator will read this value from the cgroup information then adjust the JVM based on the memory limit you define.

It looks like with Amazon Elastic Beanstalk, you can set a memory limit in your Dockerrun.aws.json. See their container definition format docs.

There are two options:

> memory
>
> Amount of memory on the container instance to reserve for the container. Specify a non-zero integer for one or both of the memory or memoryReservation parameters in container definitions.
>
> memoryReservation
>
> The soft limit (in MiB) of memory to reserve for the container. Specify a non-zero integer for one or both of the memory or memoryReservation parameters in container definitions.

I'm not an expert with Amazon Elastic Beanstalk, but from their docs it sounds like you want to set memory.


If one is unable to set the memory limit for some reason your only option at the time of writing is to ignore the warning and use the 1G defaults.

You would then likely want to downsize your environment so that you are not wasting resources. Like if you have a 4G VM, it's only going to configure the JVM to use 1G, so size your VM down to 1G (or something around there) and you'll end up using the available resource better.

huangapple
  • 本文由 发表于 2020年10月20日 18:16:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64443053.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定