--If the amount of memory specified in "Task memory" in the task definition of fargate is exceeded, the task will be forcibly terminated. --Therefore, it is necessary to adjust the maximum heap size etc. so that it does not exceed the task memory.
--Language: Kotlin --Framework: ktor --docker image: openjdk: 8-jre-alpine
Dockerfile
FROM openjdk:8-jre-alpine
ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./build/libs/my-application.jar /app/my-application.jar
WORKDIR /app
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-XX:MaxMetaspaceSize=256M", "-XshowSettings:vm", "-jar", "my-application.jar"]
Basically [ktor documentation](https://jp.ktor.work/quickstart/quickstart/docker.html#docker%E3%82%A4%E3%83%A1%E3%83%BC%E3% Based on 82% B8% E3% 81% AE% E6% BA% 96% E5% 82% 99), but added a java option.
---XX: MaxMetaspaceSize = 256M
: It is a setting that secures the maximum value of the metaspace of 256MB and does not increase it any more. By default, it can be expanded without limit, so I set the maximum value just in case.
---XshowSettings: vm
: Outputs VM settings at startup.
Be sure to specify the memory hard limit in the container definition.
The value specified here is passed to the --memory
option of docker run
.
Normally, specify the same value as the task memory.
View the Fargate task log and make sure that Max. Heap Size
is what you expected.
In this case, the hard limit is 1000MiB and the java option is "-XX: MaxRAMFraction = 2", so 500M is correct.
Recommended Posts