Spring Boot内存消耗增加到超过-Xmx选项 [英] Spring Boot memory consumption increases beyond -Xmx option

查看:719
本文介绍了Spring Boot内存消耗增加到超过-Xmx选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到Spring Boot应用程序不遵守通过Xmx选项设置的内存量. 例如:java -Xss64m -Xmx64m -jar test.jar

I noticed Spring Boot application does not obey the amount of memory set via Xmx option. For example: java -Xss64m -Xmx64m -jar test.jar

我还在控制台上打印了启动时应用程序实际使用的内存量,并显示: 最大内存:61M

I also printed on console the amount of memory really used by application at startup, and shows: Max memory: 61M

long maxBytes = Runtime.getRuntime().maxMemory();
System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");

当我在访问任何网页之前打开Windows进程时,它显示+ -105M,那么Java怎么说61M?

When I open Windows processes before accessing any web page, it shows +-105M, so how can Java say 61M?

访问任何网页后,它从+ -125M变为+ -135M.为什么会有这样的增加?它应该提供"java.lang.OutOfMemoryError:PermGen空间",但不要以这种方式增加.

After accessing any web page it goes from +-125M to +-135M. Why is there such increase? It should give "java.lang.OutOfMemoryError: PermGen space" but do not increase this way.

如果许多应用程序可能耗尽服务器的内存,这会让我感到担忧.顺便说一句,我正在使用Java 1.8_45

It makes me get worried, if many applications could run out of memory at the server. By the way, I am using Java 1.8_45

推荐答案

在监视Spring Boot应用程序之后,我发现了一些可能的原因,例如:

After monitoring the Spring Boot application, I found out some possible reasons such as:

  1. http线程数(Undertow开始于每个线程约50个线程 默认值,但您可以通过属性增加/减少所需的线程数量)
  2. 通过JNI访问本机例程(.dll,.so)
  3. 静态变量
  4. 使用缓存(内存缓存,ehcache等)
  5. 如果VM是32位或64位,则64位会使用更多的内存来运行同一应用程序,因此,如果您不需要大于1.5GB的堆,请使应用程序的运行时间保持在32位以上以节省内存.
  1. Number of http threads (Undertow starts around 50 threads per default, but you can increase / decrease via property the amount of threads needed)
  2. Access to native routines (.dll, .so) via JNI
  3. Static variables
  4. Use of cache (memcache, ehcache, etc)
  5. If a VM is 32 bit or 64 bit, 64 bit uses more memory to run the same application, so if you don't need a heap bigger than 1.5GB, so keep your application runnnig over 32 bit to save memory.

这篇关于Spring Boot内存消耗增加到超过-Xmx选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆