【问题标题】:Detecting Memory Leak in a web application检测 Web 应用程序中的内存泄漏
【发布时间】:2011-10-09 00:08:16
【问题描述】:

我们有一个用 gwt 编写并部署在 tomcat 中的 Web 应用程序。 tomcat 在 outofmemoryexception 上崩溃,所以我正在尝试使用 Jprofiler、jmap/jhat 实用程序等查找内存泄漏。

以下是我看到的问题,感谢专家帮助追查问题。

我已将 tomcat 配置为使用 -Xmx1600m -Xms1024m 运行并启用 gc 日志记录。当我在运行应用程序几个小时后看到 gc 日志时,我看到以下内容,

9850.373: [GC [PSYoungGen: 301459K->10630K(341504K)] 943137K->663019K(1269952K), 0.1711120 secs] [Times: user=0.32 sys=0.02, real=0.17 secs]
9864.412: [GC [PSYoungGen: 320588K->14287K(341376K)] 972976K->668772K(1269824K), 0.1604710 secs] [Times: user=0.24 sys=0.00, real=0.16 secs]
9874.808: [GC [PSYoungGen: 324431K->7800K(377792K)] 978916K->666111K(1306240K), 0.1253720 secs] [Times: user=0.21 sys=0.04, real=0.12 secs]
9884.888: [GC [PSYoungGen: 355320K->7639K(377920K)] 1013631K->670793K(1306368K), 0.1563460 secs] [Times: user=0.23 sys=0.01, real=0.15 secs]
9897.209: [GC [PSYoungGen: 355159K->9687K(423552K)] 1018313K->676330K(1352000K), 0.1368880 secs] [Times: user=0.22 sys=0.05, real=0.14 secs]
9913.372: [GC [PSYoungGen: 403927K->5599K(424000K)] 1070570K->675351K(1352448K), 0.1599430 secs] [Times: user=0.21 sys=0.02, real=0.16 secs]
9999.866: [GC [PSYoungGen: 399839K->6655K(468480K)] 1069591K->678050K(1396928K), 0.2453910 secs] [Times: user=0.37 sys=0.03, real=0.24 secs]
10104.177: [GC [PSYoungGen: 449919K->10830K(472576K)] 1121314K->688787K(1401024K), 0.1271810 secs] [Times: user=0.20 sys=0.03, real=0.12 secs]
10114.859: [GC [PSYoungGen: 454094K->7316K(514240K)] 1132051K->694401K(1442688K), 0.1046640 secs] [Times: user=0.15 sys=0.05, real=0.10 secs]
10127.079: [GC [PSYoungGen: 496084K->6783K(516160K)] 1183169K->699705K(1444608K), 0.1004840 secs] [Times: user=0.17 sys=0.03, real=0.10 secs]
10136.380: [GC [PSYoungGen: 495551K->8800K(516096K)] 1188473K->707881K(1444544K), 0.1615950 secs] [Times: user=0.28 sys=0.04, real=0.16 secs]
10151.757: [GC [PSYoungGen: 500704K->13808K(517696K)] 1199785K->716602K(1446144K), 0.2068230 secs] [Times: user=0.32 sys=0.09, real=0.20 secs]
10184.481: [GC [PSYoungGen: 505712K->4543K(519488K)] 1208506K->716201K(1447936K), 0.2158960 secs] [Times: user=0.32 sys=0.05, real=0.22 secs]
10206.485: [GC [PSYoungGen: 499647K->12190K(520192K)] 1211305K->728137K(1448640K), 0.2251280 secs]

我从gc.log的理解如下,

垃圾回收后年轻代正在使用 12190K。 老年代在垃圾回收后使用 728137K。

所以应用程序总共使用了 740M。我的理解是否正确?

如果不是,这个日志文件的正确解释是什么?

如果是,我还使用 htop(我在 linux 上运行它)查看了系统资源使用情况,这表明 tomcat 进程正在使用 1419M。

为什么内存使用量不同?

感谢您的帮助! 谢谢。

【问题讨论】:

  • 尝试添加启动标志 -XX:+HeapDumpOnOutOfMemoryError 以进行进一步诊断。下次 JVM 内存不足时,它将转储堆中的内容。这应该会给你更多的信息。 oracle.com/technetwork/java/javase/memleaks-137499.html#gdyrr
  • 也基于年轻一代的大小,我在提供的日志中没有看到 OOMException。例如您的最后一个条目:499647K->12190K 年轻一代恢复了大约 95%。老一代从 1211305K->728137K 减少了大约 45%。在 1600 米处,您的帽子似乎有很多空间
  • 我已经添加了-XX:+HeapDumpOnOutOfMemoryError 但还没有发生OOM。
  • 出于分析目的,hprof + MAT 可能会向您显示泄漏嫌疑人。您必须对应用程序进行负载测试才能获得有价值的结果
  • 我正在使用 jprofiler 和 jconsole,可以看到 gc 正在恢复大部分已用空间。当应用程序被很多用户访问时,内存使用量增加并且 gc 收集得很好,但是我们的 Web 服务器被操作系统杀死,说以下错误 Jul 18 04:55:31 seqwd5 kernel: Out of memory: Killed process 16333 , UID 501, (java)。 7 月 18 日 04:55:31 seqwd5 内核:java 调用了 oom-killer:gfp_mask=0x201d2,order=0,oomkilladj=0 消息

标签: tomcat memory memory-leaks


【解决方案1】:

GWT Requestfactory 中存在内存泄漏,该问题已在 2.4 中修复。我刚刚升级到那个,一切都很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-17
    • 2020-02-14
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多