5

我正在使用 6.0.20 我在服务器上运行了许多 Web 应用程序,随着时间的推移,大约 3 天,服务器需要重新启动,否则服务器崩溃并无响应。

我对 JVM 有以下设置:

-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20\logs

这为我提供了一个使用 Java VisualVM 加载的 hprof 文件,该文件标识以下内容:

byte[] 37,206   Instances | Size 86,508,978
int[] 540,909   Instances | Size 55,130,332
char[] 357,847  Instances | Size 41,690,928

清单还在继续,但我如何确定导致这些问题的原因?

我正在使用 New Relic 来监控 JVM,似乎只出现了一个错误,但它是一个反复出现的错误,org.apache.catalina.connector。客户端中止异常。是否有可能当用户会话中止时,创建的任何数据库连接或变量都没有关闭,因此被孤立?

有一个功能在每个 Web 应用程序中都被大量使用,不确定这是否与泄漏有关:

public static String replaceCharacters(String s)
{
    s = s.replaceAll("  ", " ");
    s = s.replaceAll(" ", "_");
    s = s.replaceAll("\351", "e");
    s = s.replaceAll("/", "");
    s = s.replaceAll("--", "-");
    s = s.replaceAll("&", "and");
    s = s.replaceAll("&", "and");
    s = s.replaceAll("__", "_");
    s = s.replaceAll("\\(", "");
    s = s.replaceAll("\\)", "");
    s = s.replaceAll(",", "");
    s = s.replaceAll(":", "");
    s = s.replaceAll("\374", "u");
    s = s.replaceAll("-", "_");
    s = s.replaceAll("\\+", "and");
    s = s.replaceAll("\"", "");
    s = s.replaceAll("\\[", "");
    s = s.replaceAll("\\]", "");
    s = s.replaceAll("\\*", "");
    return s;
}

是否有可能当用户连接被中止时,例如用户浏览器关闭或用户离开站点时所有变量、连接等都被清除/释放,但 GC 不应该处理吗?

以下是我的 JVM 设置:

-Dcatalina.base=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20
-Dcatalina.home=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20
-Djava.endorsed.dirs=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20\endorsed
-Djava.io.tmpdir=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20\conf\logging.properties
-Dfile.encoding=UTF-8
-Dsun.jnu.encoding=UTF-8
-javaagent:c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20\newrelic\newrelic.jar
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=c:\tomcat\Websites\private\mydomain\apache-tomcat-6.0.20\logs
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false vfprintf
-Xms1024m
-Xmx1536m

我错过了什么吗?服务器有 3GB 内存。

任何帮助将非常感激 :-)

4

3 回答 3

2

... but how do I determine what is causing these issues?

You need to use a dump analyser that allows you to see what is making these objects reachable. Pick an object, and see what other object or objects refer to it ... and work backwards through the chains until you find either a "GC root" or or some application-specific class that you recognise.

Here are a couple of references on analysing memory snapshots and memory profilers:

Once you have identified that, you've gone most of the way to identifying the source of your storage leak.


That function has no direct bearing on the leak. It certainly won't cause it. (It could generate a lot of garbage String objects ... but that's a different issue.)

于 2013-07-30T09:40:33.913 回答
2

我将所有项目迁移到 Tomcat 7.0.42 并且我的错误消失了,我们的网站更加稳定且速度稍快,我们使用的内存更少,cpu 使用率也更好。

于 2013-09-03T16:03:05.083 回答
0

在本地开发环境中启动服务器,附加分析器(最好是您的工具包),定期进行堆转储,您将看到对象字节 [] 的增长,您实际上可以byte[]使用此工具将它们与您的应用程序类泄漏它,这将帮助您识别缺陷在代码中

于 2013-07-29T16:14:56.217 回答