1

It seems that no matter what I try, running java -XshowSettings:vm -version on my container yields the same output

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

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment 18.9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9, mixed mode, sharing)

I can't figure out how to increase the max heap size from 494.94M.

Here's my Dockerfile

FROM maven:3.6.3-openjdk-11-slim AS builder
WORKDIR /app
COPY pom.xml .
COPY src src
RUN mvn package
ARG JAR_FILE=target/*.jar
RUN java -Djarmode=layertools -jar ${JAR_FILE} extract

FROM openjdk:11-jre-slim
WORKDIR /app
EXPOSE 8081
COPY --from=builder /app/dependencies/ ./
COPY --from=builder /app/spring-boot-loader/ ./
COPY --from=builder /app/snapshot-dependencies/ ./
COPY --from=builder /app/application/ ./
ENV JAVA_OPTS="-XX:MinRAMPercentage=30 -XX:MaxRAMPercentage=90"
CMD java $JAVA_OPTS org.springframework.boot.loader.JarLauncher

The memory of my ECS task is set to 2048, so setting the max heap at 90% I would expect to see something closer to that.

I have also tried overriding JAVA_OPTS directly in the ECS task definition as well. I keep getting OutOfMemory errors and could really use some help!

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
secondbreakfast
  • 4,194
  • 5
  • 47
  • 101

1 Answers1

2

One option is to configure -Xmx option directly. By default OpenJDK will usually allocate heap with 25% of RAM. Since you are on Java 11 you should have Docker support enabled and it looks like correctly recognizes ECS task memory limit because 2 GB * 25% = 512 MB which roughly matches what you see with 494.94 MB.

Second route is to configure -XX:+UseCGroupMemoryLimitForHeap option to enable more seamless integration with Docker. You can check out this article which explains it as:

It allows setting the heap to the cgroup memory limit. The JVM reads from /sys/fs/cgroup/memory/memory.limit_in_bytes and uses that value instead of -XX:MaxRAM.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111