2

I'm running a Java REST app with Apache JavaSpark in this container, but I noticed that each request is adding the memory usage and not decreasing after the request is done. My first guess was that I had forgotten to close some stream/buffer (this app deal with a lot of file manipulation), but I reviewed all the code and looks like everything is being closed.

Here is my Dockerfile:

FROM maven:3.5-jdk-8-alpine

WORKDIR /code

ADD pom.xml /code/pom.xml

RUN ["mvn", "dependency:resolve"]

ADD src /code/src

RUN ["mvn", "package"]

EXPOSE 1337

CMD exec java -jar "target/app.jar"

Here is the docker stats:

CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDS
2db8b2f5fd72        0.16%               66.36 MiB / 1.952 GiB   3.32%               12.9 kB / 106 kB    0 B / 0 B           23
gbenja
  • 25
  • 1
  • 4

1 Answers1

0

Java usually allocates memory that has previously reserved, it only frees it when you restart the process. You can see this post that gives the full explanation.

java.exe process uses more memory and does not free it up

German
  • 1,449
  • 12
  • 13
  • Yeah, looks like you are right.! I set a small memory limit for the container, so I tried to force a java.lang.OutOfMemoryError, but I couldn't, when the memory usage was close to the limit it is reduced. – gbenja Jun 05 '17 at 21:07