Tomcat服务内存超过最大容量而无故障 [英] Tomcat service memory exceeds max without failure

查看:424
本文介绍了Tomcat服务内存超过最大容量而无故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多文章,但显然我所缺少的东西.我有一个Tomcat服务,安装有:

I've read a multitude of posts but clearly I'm missing something in my understanding. I have a Tomcat service, which is installed with:

--JvmMx=1000
--JvmMs=128

我已经通过以下电话验证了这些设置是否成功:

I've verified that these settings are successful via calls such as:

PsExec.exe -s {jdk}\bin\jinfo.exe -flag MaxHeapSize {pid}

但是,此服务的tomcat7.exe进程持续增长,超出此最大值3倍或更多倍,直到将服务器带入爬网为止.奇怪的是,这只是一台服务器上的问题.在其他任何地方,它都是相当恒定的,并保持在极限之下.我还在开发环境中寻找内存泄漏,却没有发现.

However, the tomcat7.exe process for this service consistently grows, exceeding this maximum by factors of 3 or more until it brings the server to a crawl. Weirdly, this is only an issue on one server; everywhere else it's fairly constant and remains under the limit. I've also looked for memory leaks in my development environment and have found none.

要调试此功能,我尝试像这样强制使用GC:

To debug this, I've tried forcing the GC like so:

 PsExec.exe -s {jdk}\bin\jcmd.exe {pid} GC.run

但这似乎没有效果.因此,接下来我将其添加到安装中,以进行jconsole监视:

But this seems to have no effect. So next I set it up for jconsole monitoring by adding this to the installation:

tomcat7.exe //US//%SERVICE_NAME% ++JvmOptions="-Dcom.sun.management.jmxremote"
tomcat7.exe //US//%SERVICE_NAME% ++JvmOptions="-Dcom.sun.management.jmxremote.port=8086"
tomcat7.exe //US//%SERVICE_NAME% ++JvmOptions="-Dcom.sun.management.jmxremote.ssl=false"
tomcat7.exe //US//%SERVICE_NAME% ++JvmOptions="-Dcom.sun.management.jmxremote.authenticate=false"

现在(当然!)它表现得很好. GC显然可以正常工作,并且进程内存仍低于限制.

Now (of course!) it's well-behaved. GC is clearly working and the process memory is staying below the limit.

我很困惑.最大堆是1 GB,永久内存是90 MB,默认为堆栈大小,大约128KB?线程数(不会增加)是仅"67.那么进程内存如何增加到3+ GB?为什么不抛出内存不足异常?

I'm baffled. Max heap is 1 GB, permanent memory is 90 MB, stack size is defaulted, so about 128KB? And the thread count, which does not grow, is "only" 67. So how can the process memory rise to 3+ GB? And why isn't it throwing an out of memory exception?

即使是现在,根据jconsole进行的行为良好"服务也仅使用大约50 MB的堆,并在57个线程上运行.然而,任务管理器显示使用800 MB的71个线程.我认为差异是由于Tomcat造成的,是吗?请帮助我填补我的理解空白.

Even now, the "well-behaved" service according to jconsole is only using about 50 MB of heap, running on 57 threads. Yet Task Manager is showing 71 threads using 800 MB. I assume the difference is due to Tomcat, is it? Please help me fill in the gaps of my understanding.

推荐答案

Java使用的内存远远超过了Java堆空间所需的内存.它被称为本机内存",不包含在您提到/检查的任何内存空间中.

Java uses more memory than just what you need for the Java heap spaces. It's called "native memory" and isn't counted in any of the memory spaces you've been mentioning / checking.

这篇文章会让您大开眼界: http://www.evanjones.ca/java-native-leak-bug. html

This post will open your eyes: http://www.evanjones.ca/java-native-leak-bug.html

(FWIW,将服务器进程的-Xms-Xmx设置为不同的值只是浪费时间.将它们设置为相同的值,这样就不需要重新调整堆大小了.最多可以达到最大堆大小.如果您要向服务器进程配置例如1GiB,则最好立即使用它.)

(FWIW, setting -Xms and -Xmx to different values for a server process is simply a waste of time. Set them to the same value so that the heap doesn't need to be re-sized a bunch of times on the way "up" to the max heap size. If you are going to provision e.g. 1GiB to the server process, you may as well allow it to be used right away.)

这篇关于Tomcat服务内存超过最大容量而无故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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