如何在AWS ECS中增加Java堆大小?

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

How to Increase Java Heap Size in AWS ECS?

问题

我在Java SpringBoot中开发了一个REST API。我已将此API部署为AWS ECS中的Docker容器。我在AWS任务中分配了2048 MB作为硬内存和1024作为软内存。在ECS启动Docker容器后,我访问了Docker容器并执行了以下命令:

> java -XX:+PrintFlagsFinal -version | grep HeapSize

我获得了以下结果:

 uintx ErgoHeapSizeLimit = 0 {product}
    uintx HeapSizePerGCThread = 87241520 {product}
    uintx InitialHeapSize := 33554432 {product}
    uintx LargePageHeapSizeThreshold = 134217728 {product}
    **uintx MaxHeapSize := 536870912** {product}

结果中显示的MaxHeapSize为536870912,约为536 MB(大约是软内存的一半)

我想知道如何在AWS ECS环境中将此堆大小增加至少到800 MB。

我知道如何使用命令java -Xmx800m设置堆大小,但我不知道在AWS ECS环境中在哪里执行此命令。

英文:

I have REST API developed in Java SpringBoot. I have deployed this API as a docker container in AWS ECS. I have allocated 2048 MB as hard memory and 1024 as soft memory in the AWS Task. After ECS launches the docker container, I access the docker container and executed the following command

> java -XX:+PrintFlagsFinal -version | grep HeapSize

I get the following result

 uintx ErgoHeapSizeLimit                         = 0                   {product}
    uintx HeapSizePerGCThread                       = 87241520                            {product}
    uintx InitialHeapSize                          := 33554432                            {product}
    uintx LargePageHeapSizeThreshold                = 134217728                           {product}
    **uintx MaxHeapSize                              := 536870912**                           {product}

The MaxHeapSize shown in the result is 536870912 which is approx 536 MB (around half of the soft memory)

I would like to know how can I increase this heap size to at least 800 MB in the AWS ECS environment.

I know how to set the heap size using the command java -Xmx800m, but I do not know where to execute this command in the AWS ECS enviornment.

答案1

得分: 3

对我来说,通过在我的 ECS 任务定义中设置环境变量 JAVA_TOOL_OPTIONS 来实现,就像这样:

环境变量
JAVA_TOOL_OPTIONS -XX:InitialHeapSize=1g -XX:MaxHeapSize=2g

希望能对你有所帮助!

顺便说一下,我的容器是在 Amazon Corretto JDK 版本 8 下运行的。

英文:

For me, it worked by setting the environment variable JAVA_TOOL_OPTIONS in my ECS Task Definition like this:

Environment Variable Value
JAVA_TOOL_OPTIONS -XX:InitialHeapSize=1g -XX:MaxHeapSize=2g

I hope this helps!

BTW, my container was running with Amazon Corretto JDK version 8.

答案2

得分: 2

在你的Dockerfile中添加xmx属性。例如,命令为java -Xmx800m your_jar。

英文:

Add xmx property in your dockerfile. eg cmd java -Xmx800m your_jar

答案3

得分: 2

以下是您要翻译的内容:

对我来说,-Xmx 似乎不被 ECS 忽略。

我增加了任务的 vCPU 和内存参数,希望增加堆大小。

我在容器命令的覆盖中使用了参数 -XX:MaxRAMPercentage=80.0。最终它起效了。

英文:

For me the -Xmx seemed not to be ignored by ECS.

I increased the Task vCPU and memory parameters, and wanted the heap size to be increased.

I used the parameter -XX:MaxRAMPercentage=80.0 in the override of the container Command. It finally worked.

huangapple
  • 本文由 发表于 2020年9月7日 16:08:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63773664.html
匿名

发表评论

匿名网友

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

确定