jeudi 5 novembre 2020

How to set memory limit for your Java containers?


In earlier versions of Java 8 (before update version 192), the JVM has no knowledgeof any limits that the container will enforce: when it inspects the environment to find out how much memory is available so it can calculate its default heap size, it will see all the memory on the machine (instead of,as we would prefer, the amount of memory the Docker container is allowed touse)

The real issue here is the memory: the maximum size of the heap will potentially be larger than the memory assigned to the Docker container.

When the heap grows to that size, the Docker container (and hence the JVM) will be killed.

As java 11 (10+) can automatically detect the container's memory you can set memory limit on your container and it should WAI:
docker run -m 512 .... 

 https://www.upnxtblog.com/index.php/2019/03/14/how-to-set-memory-limit-for-your-java-containers/ 

https://stackoverflow.com/questions/64703776/how-to-set-memory-limit-for-java-11-inside-docker/64705449#64705449

https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits

-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap : permet de ne limiter la taille de la JVM qu'à ce que peux supporter le conteneur. 

-XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics : log des informations sur l'occupation des espaces mémoires propres à la JVM.


Aucun commentaire:

Enregistrer un commentaire

to criticize, to improve