KurioZ7
KurioZ7

Reputation: 6349

How to Increase Java Heap Size in 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.

Upvotes: 6

Views: 18599

Answers (3)

Eduardo Andrade
Eduardo Andrade

Reputation: 966

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.

Upvotes: 5

Erwan
Erwan

Reputation: 61

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.

Upvotes: 3

Saurabh Nigam
Saurabh Nigam

Reputation: 823

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

Upvotes: 2

Related Questions