java 内存耗尽 Xmx 和 Xms

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45760977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:52:48  来源:igfitidea点击:

Memory running out side of Xmx and Xms

javamemory-managementjconsole

提问by user1864311

I have run into an issue with a java application I wrote causing hardware performance issues. The problem (I'm fairly certain), is that a few of the machines that I'm running the application on only have 1GB of memory. When I start my java application, I"m setting the heap size to -Xms 512m -Xmx 1024m.

我编写的 Java 应用程序遇到了问题,导致硬件性能问题。问题(我很确定)是我运行应用程序的一些机器只有 1GB 的内存。当我启动我的 Java 应用程序时,我将堆大小设置为 -Xms 512m -Xmx 1024m。

My first question, is my assumption correct that this will obviously cause performance problems because I'm allocating all of the machines memory to the java heap?

我的第一个问题,我的假设是否正确,因为我将所有机器内存分配给 java 堆,这显然会导致性能问题?

This leads to another question. I'm running jconsole on the app and monitoring the apps memory usage. What I'm seeing is that the app consumes about 30mb at startup, gets to about 150mb and the garbage collector runs and it goes back down to 30mb. What I'm also seeing using top on the pid is that the application starts by using about 6% memory then slowly climbs up to about 20%. I do not understand this. Why would it only get up to 20% memory usage when I'm allocating 1GB to it. Shouldn't it go to 100%. Also, why is it using that much memory (20%) when it doesn't appear that the app ever uses more than 150mb?

这就引出了另一个问题。我在应用程序上运行 jconsole 并监视应用程序内存使用情况。我看到的是应用程序在启动时消耗了大约 30mb,达到大约 150mb,垃圾收集器运行后又回到 30mb。我还看到在 pid 上使用 top 是应用程序从使用大约 6% 的内存开始,然后慢慢攀升到大约 20%。我不明白。当我为它分配 1GB 时,为什么它最多只能使用 20% 的内存。不应该是100%吗?此外,当应用程序似乎从未使用超过 150mb 的内存时,为什么它使用那么多内存 (20%)?

I think its pretty obvious I need to adjust my Xms and Xmx and that should resolve the issue, but I'm trying to understand better what exactly is happening.

我认为很明显我需要调整我的 Xms 和 Xmx,这应该可以解决问题,但我试图更好地了解到底发生了什么。

回答by Norbert van Nobelen

Two possibilities for the memory use:

内存使用的两种可能性:

Your app just does not use that much memory

你的应用只是没有使用那么多内存

Or

或者

Your app does not use that much memory fast enough.

您的应用程序使用的内存不够快。

What happens:

怎么了:

The garbage collector has several points where it will execute:

垃圾收集器有几个执行点:

  1. Just scheduled: It will clean up easy to remove objects

  2. Full collection: This runs when you hit the set memory limits.

  1. 刚预定:它会清理容易移除的物体

  2. 完整集合:当您达到设置的内存限制时运行。

If options 1, the general much lower impact quick collection, can keep your memory use under control, it will not hit the full collection unless it the JVM GC options are set to run a full on a schedule.

如果选项 1,通常影响低得多的快速收集,可以控制您的内存使用,它不会命中完全收集,除非 JVM GC 选项设置为按计划完全运行。

With your application I would start setting lower xmx/xms values so that more guaranteed resources are left for the OS, and maybe some paging is prevented.

对于您的应用程序,我将开始设置较低的 xmx/xms 值,以便为操作系统留下更多有保证的资源,并且可能会阻止某些分页。