0

I am running a docker container which has bundled the java application (Java 1.8).

My problem is my IOT device has limited memory (RAM 2 GB and need to share by 5 application).

When I tried to run my application I have reserved 450 MB RAM and allocated 50% to JVM as bellow:

FROM openjdk:8u252-jre-slim-buster

ADD myIotApp.jar myIotApp.jar
ADD jsr47min.properties jsr47min.properties

CMD java -Djava.util.logging.config.file=jsr47min.properties -jar -XX:+UseContainerSupport -XX:MaxRAMPercentage=50.0 -XshowSettings:vm myIotApp.jar

I understand JVM needs some memory to run smoothly and there are some compatibility issue (As mentioned in the bellow thread): https://developers.redhat.com/blog/2017/03/14/java-inside-docker/

But I have taken suggestion to overcome this.

But I have observed as soon as application executes some complex operation it consumes almost 80% memory but never releases back once computation is done.

Is there any way to fix this problem?

or

Is java a good choice for such environment?

IAMSKU
  • 33
  • 1
  • 6
  • "...but never releases back once computation is done." - Does you code have memory leaks? – Prashant Pandey Oct 18 '20 at 08:27
  • Thanks Prashant for the suggestion... Yes for application memory I am handling cleanup of the memory which is helping to reduce memory footprint, but the problem comes while running the application for the longer time for example more then 1-3 days. For basic data type in the scope of function for example string array etc I believe garbage collector will does it jobs once function scope will be completed. – IAMSKU Oct 18 '20 at 08:55

1 Answers1

0

I guess java should not be the language of choice in your environment. But sometimes that choice has been taken already and you have to run that application in your restricted device. So there are a few things you can look out for:

As a developer try to make the application use as little memory as possible. This can be done by looking at how much information is stored in RAM, caches etc. Use algorithms that can stream data and store/load from disk. Ensure your application has no memory leak and releases memory as early as possible.

As a system integrator try to ensure even if the JVM misbehaves the system stability is not at stake. Put reasonable memory limits on the JVM and make it rather die on OutOfMemoryError than compromise other processes. To be on the safe side also configure memory limits on the container. Then configure Docker to automatically restart the container if the application dies.

Queeg
  • 7,748
  • 1
  • 16
  • 42