Boot消耗过多的RAM

Boot消耗过多的RAM

本文介绍了Spring Boot消耗过多的RAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在春季启动中创建了一些服务,我有11个胖jar,并将它们部署在docker容器中,我的疑问是每个jar都消耗了1到1.5 GB的RAM,而没有任何使用,我通过运行来检查RAM:

I have created some services in spring boot, I have 11 fat jars and I deploy them in docker containers, my doubt was that every jar was consuming between 1 and 1.5 GB of RAM without any use, I check the RAM by running:

docker stats containername

起初我以为是Java容器,所以我尝试将其更改为使用alpine的容器,但没有任何变化,因此我认为唯一的问题是我的jar.有没有办法更改jar正在使用的RAM?还是这种行为是正常的,因为每个jar都有一个嵌入式的tomcat?或者将一些罐子放在一起作为战争来部署,并在一组罐子"中仅使用一个tomcat更好?有人可以分享他/她的经验吗?,

At first I thought that it was the java container and I tried to change to one that uses alpine but nothing changed, so I think the only problem is my jar. Is there a way to change the RAM that the jar is using? Or this behavior is normal because every jar has an embedded tomcat? Or maybe is better to put some jars together and deploy them as war and use only one tomcat for a group of "jars"? Can someone share his/her experience?,

谢谢.

推荐答案

您可以使用 -e JAVA_OPTS =-Xmx64M -Xms64M" 设置Docker容器的内存使用情况.

You can set memory usage of docker container using -e JAVA_OPTS="-Xmx64M -Xms64M".

docker文件:

FROM openjdk:8-jre-alpine
VOLUME ./mysql:/var/lib/mysql
ADD /build/libs/application.jar app.jar
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar

图像运行:

 docker run -d --name container-name -p 9100:9100 -e JAVA_OPTS="-Xmx512M -Xms512M"   imagename:tag

在这里,我设置了512Mb的内存使用率.您可以设置1g或根据您的要求.使用此命令运行后,检查您的内存使用情况.最高可达512Mb.

Here i set 512Mb memory usage . you can set 1g or as per your requirement. After run using this check your memory usage. it will max 512Mb.

这篇关于Spring Boot消耗过多的RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:53