Search code examples
dockerdebuggingheroku

How to debug unexpectedly high memory use with Docker in Heroku?


I am deploying a small app in Docker to Heroku. The issue I see while running locally, the setup takes up to 400 MB. On the Heroku, while running, it skyrockets to 1.7 GB of RAM.

Dockerfile:

FROM bellsoft/liberica-openjdk-alpine-musl:11
ENV PORT=$PORT
ARG ENV
ENV STARTUP_ENV=$ENV
COPY /target/app-0.0.1-SNAPSHOT.jar /app-0.0.1-SNAPSHOT.jar
RUN echo $ENV
CMD java -Dspring.profiles.active=$STARTUP_ENV -Djava.security.egd=file:/dev/./urandom -Dserver.port=$PORT -jar /app-0.0.1-SNAPSHOT.jar

I cannot show the code, but the visualvm showed that the Kotlin app never reached more than 80 MB RAM benchmark.

How can I debug this issue?

P.S. The main concern that the app restarts automatically while running, and I lose critical data.

UPDATE:

As I didn't an answer, so I raised an issue in Heroku repo.


Solution

  • This was purely a java issue inside the Docker, not a Heroku issue.

    I forgot to specify -Xms and -Xmx keys. Beware that they are different by default, so you need to explicitly specify how much RAM you allow to prevent Heroku from constantly restating your app after a while.

    Example of my Docker file:

    FROM azul/zulu-openjdk-alpine:11
    ENV PORT=$PORT
    ARG ENV
    ENV STARTUP_ENV=$ENV
    ENV VERSION=0.0.1
    
    COPY /target/app-$VERSION.jar /app-$VERSION.jar
    RUN echo $ENV
    CMD java -Xms256m -Xmx512m -Dspring.profiles.active=$STARTUP_ENV -Djava.security.egd=file:/dev/./urandom -Dserver.port=$PORT -jar /app-$VERSION.jar