- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的一台生产机器出现了一个奇怪的问题。它承载了一个执行 CMS(并发标记和清除)的 Java 应用程序,但它只清除了老年代的一小部分。我怀疑内存泄漏并尝试堆转储。但是堆转储之前的 Full GC 几乎清理了所有的老年代。发生了什么?我从未见过 Java 垃圾回收的这种行为。通常 CMS 和 Full GC 应该收集大约相同数量的垃圾,现在 CMS 多保留了大约 10GB。
GC 日志:
**2016-01-04T07:37:40.196+0000: 431200.698: [GC [1 CMS-initial-mark: 21633423K(27336704K)] 22826703K(30101504K), 4.3910840 secs] [Times: user=4.40 sys=0.01, real=4.39 secs]
2016-01-04T07:37:44.588+0000: 431205.090: [CMS-concurrent-mark-start]
2016-01-04T07:38:08.718+0000: 431229.220: [CMS-concurrent-mark: 18.213/24.131 secs] [Times: user=126.00 sys=2.22, real=24.13 secs]
2016-01-04T07:38:08.718+0000: 431229.220: [CMS-concurrent-preclean-start]
2016-01-04T07:38:08.843+0000: 431229.345: [CMS-concurrent-preclean: 0.118/0.125 secs] [Times: user=0.29 sys=0.00, real=0.12 secs]
2016-01-04T07:38:08.843+0000: 431229.345: [CMS-concurrent-abortable-preclean-start]
CMS: abort preclean due to time 2016-01-04T07:38:13.906+0000: 431234.408: [CMS-concurrent-abortable-preclean: 4.975/5.063 secs] [Times: user=10.18 sys=0.03, real=5.06 secs]
2016-01-04T07:38:14.001+0000: 431234.503: [GC[YG occupancy: 1312993 K (2764800 K)]2016-01-04T07:38:14.001+0000: 431234.503: [Rescan (parallel) , 4.6981760 secs]2016-01-04T07:38:18.699+0000: 431239.202: [weak refs processing, 0.0002970 secs]2016-01-04T07:38:18.700+0000: 431239.202: [scrub string table, 0.0006900 secs] [1 CMS-remark: 21633423K(27336704K)] 22946417K(30101504K), 4.6993310 secs] [Times: user=105.40 sys=0.36, real=4.70 secs]
2016-01-04T07:38:18.701+0000: 431239.203: [CMS-concurrent-sweep-start]
2016-01-04T07:38:27.967+0000: 431248.469: [CMS-concurrent-sweep: 9.160/9.267 secs] [Times: user=17.91 sys=0.10, real=9.26 secs]
2016-01-04T07:38:27.968+0000: 431248.470: [CMS-concurrent-reset-start]
2016-01-04T07:38:28.028+0000: 431248.531: [CMS-concurrent-reset: 0.061/0.061 secs] [Times: user=0.14 sys=0.00, real=0.06 secs]**
2016-01-04T07:38:30.801+0000: 431251.303: [GC [1 CMS-initial-mark: 21633105K(27336704K)] 23039228K(30101504K), 5.6079370 secs] [Times: user=5.60 sys=0.01, real=5.61 secs]
2016-01-04T07:38:36.409+0000: 431256.911: [CMS-concurrent-mark-start]
2016-01-04T07:38:54.673+0000: 431275.175: [CMS-concurrent-mark: 17.807/18.264 secs] [Times: user=119.97 sys=1.66, real=18.26 secs]
2016-01-04T07:38:54.673+0000: 431275.175: [CMS-concurrent-preclean-start]
2016-01-04T07:38:54.799+0000: 431275.301: [CMS-concurrent-preclean: 0.119/0.126 secs] [Times: user=0.25 sys=0.00, real=0.13 secs]
2016-01-04T07:38:54.799+0000: 431275.301: [CMS-concurrent-abortable-preclean-start]
CMS: abort preclean due to time 2016-01-04T07:39:01.382+0000: 431281.884: [CMS-concurrent-abortable-preclean: 6.478/6.583 secs] [Times: user=12.23 sys=0.06, real=6.58 secs]
2016-01-04T07:39:01.487+0000: 431281.989: [GC[YG occupancy: 1596183 K (2764800 K)]2016-01-04T07:39:01.487+0000: 431281.989: [Rescan (parallel) , 3.5737630 secs]2016-01-04T07:39:05.061+0000: 431285.563: [weak refs processing, 0.0002690 secs]2016-01-04T07:39:05.061+0000: 431285.563: [scrub string table, 0.0005740 secs] [1 CMS-remark: 21633105K(27336704K)] 23229288K(30101504K), 3.5747910 secs] [Times: user=80.26 sys=0.27, real=3.58 secs]
2016-01-04T07:39:05.062+0000: 431285.564: [CMS-concurrent-sweep-start]
2016-01-04T07:39:21.895+0000: 431302.397: [CMS-concurrent-sweep: 9.449/16.834 secs] [Times: user=27.52 sys=0.16, real=16.83 secs]
2016-01-04T07:39:21.895+0000: 431302.397: [CMS-concurrent-reset-start]
2016-01-04T07:39:21.995+0000: 431302.497: [CMS-concurrent-reset: 0.099/0.099 secs] [Times: user=0.23 sys=0.01, real=0.10 secs]
2016-01-04T07:39:24.104+0000: 431304.606: [GC [1 CMS-initial-mark: **21631742K(27336704K)**] 23455261K(30101504K), 5.6592940 secs] [Times: user=5.67 sys=0.00, real=5.66 secs]
2016-01-04T07:39:29.764+0000: 431310.266: [CMS-concurrent-mark-start]
2016-01-04T07:39:56.859+0000: 431337.361: [CMS-concurrent-mark: 19.813/27.096 secs] [Times: user=140.17 sys=2.62, real=27.10 secs]
2016-01-04T07:39:56.859+0000: 431337.361: [CMS-concurrent-preclean-start]
2016-01-04T07:39:57.102+0000: 431337.604: [CMS-concurrent-preclean: 0.152/0.242 secs] [Times: user=0.35 sys=0.00, real=0.24 secs]
2016-01-04T07:39:57.102+0000: 431337.604: [CMS-concurrent-abortable-preclean-start]
CMS: abort preclean due to time 2016-01-04T07:40:03.016+0000: 431343.518: [CMS-concurrent-abortable-preclean: 5.376/5.914 secs] [Times: user=11.65 sys=0.05, real=5.91 secs]
2016-01-04T07:40:03.016+0000: 431343.518: [GC[YG occupancy: 2045175 K (2764800 K)]2016-01-04T07:40:03.016+0000: 431343.518: [Rescan (parallel) , 3.4843400 secs]2016-01-04T07:40:06.501+0000: 431347.003: [weak refs processing, 0.0002510 secs]2016-01-04T07:40:06.501+0000: 431347.003: [scrub string table, 0.0006220 secs] [1 CMS-remark: **21631742K(27336704K)**] 23676918K(30101504K), 3.4853760 secs] [Times: user=78.31 sys=0.27, real=3.49 secs]
2016-01-04T07:40:06.502+0000: 431347.004: [CMS-concurrent-sweep-start]
{Heap before GC invocations=1832 (full 5077):
par new generation total 2764800K, used 2166647K [0x00000000bae00000, 0x0000000176600000, 0x0000000176600000)
eden space 2457600K, 77% used [0x00000000bae00000, 0x000000012e6a4c90, 0x0000000150e00000)
from space 307200K, 89% used [0x0000000150e00000, 0x0000000161939318, 0x0000000163a00000)
to space 307200K, 0% used [0x0000000163a00000, 0x0000000163a00000, 0x0000000176600000)
concurrent mark-sweep generation total 27336704K, used 21631644K [0x0000000176600000, 0x00000007fae00000, 0x00000007fae00000)
concurrent-mark-sweep perm gen total 49956K, used 30116K [0x00000007fae00000, 0x00000007fdec9000, 0x0000000800000000)
**2016-01-04T07:40:12.775+0000: 431353.277: [Full GC2016-01-04T07:40:12.775+0000: 431353.277: [CMS2016-01-04T07:40:17.924+0000: 431358.426: [CMS-concurrent-sweep: 9.211/11.422 secs] [Times: user=16.59 sys=0.15, real=11.42 secs]
(concurrent mode interrupted): 21631644K->4907878K(27336704K), 39.2467600 secs] 23798292K->4907878K(30101504K), [CMS Perm : 30116K->28023K(49956K)], 39.2468730 secs] [Times: user=39.24 sys=0.05, real=39.25 secs]**
同一个应用在另一台使用Cent OS 5、java 7的机器上正常运行。
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1581
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -verbose:gc -XX:+PrintGCDetails
-XX:+UseCompressedOops -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC
-XX:+PrintTenuringDistribution -XX:+UseConcMarkSweepGC
-Xloggc:/usr/local/app/logs/current-gc.log -Xms29g -Xmx29g -XX:NewSize=3000m
-XX:SurvivorRatio=8 -XX:CMSInitiatingOccupancyFraction=70
-XX:+UseCMSInitiatingOccupancyOnly
-Dsun.rmi.dgc.client.gcInterval=0x7FFFFFFFFFFFFFFE
-Dsun.rmi.dgc.server.gcInterval=0x7FFFFFFFFFFFFFFE
-cp /usr/local/app/conf:/usr/local/app/app.jar:/usr/local/app/lib/* -Xdebug
-Xrunjdwp:transport=dt_socket,address=8099,server=y,suspend=n
-Dvisualvm.display.name=App -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/usr/local/app/logs/
-XX:ErrorFile=/usr/local/app/logs/hs_err_pid%p.log
-Djgroups.tcpgossip.initial_host=localhost
-Dlog4j.hostname=host7.company.com com.company.app.service.App
更新:问题仍未解决。我已经尝试了所有方法:更新操作系统包和内核,将 Java 更新到最新版本 Java 1.7.0_80,回滚应用程序版本,但没有成功。
我也验证了以前的 GC 日志,发现这个问题不是永远的。它在大约一个月前部署后开始。
最佳答案
我怀疑由于非常大的堆,您的应用程序还没有提出 Major collection 的需要:任期 Old Gen
和 Survivor Space
都没有用完。
如果您不这样认为,(即使满足任何一个条件也未触发主要收集),请分享您的 gclog 语句。
不同的注意事项:由于您使用的是大堆,因此首选 G1GC。
编辑:
-XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly
默认情况下,CMS GC 使用一组启发式规则来触发垃圾收集。这使得 GC 更不可预测,并且通常倾向于延迟收集,直到老年代几乎被占用。
-XX:+UseCMSInitiatingOccupancyOnly
防止使用 GC 启发式方法。
-XX:CMSInitiatingOccupancyFraction
通知 Java VM 何时应触发 CMS。
您已将其配置为 70%。如果你的 OldGen [Max heap (29G) - new Gen (3G)] 达到限制的 70%,GC 将被触发。作为 GC 的一部分,第一个次要 GC 被触发。如果此时 minor GC 没有释放足够的空间来分配新对象,则会触发 Major GC 或 Full GC。
看看这个article了解更多详情。
我发现了另一个相关的 SE 问题:CMS garbage collector - when does it run? .也看看这个。
关于java - 为什么并发标记和清除 (CMS) 没有清理与 Full GC 相同数量的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431322/
我在看 this post在 GitHub 中,但我无法理解 OP 的含义: “全表达式”暗示是一种表达式,但有时又不是。 我的解释是“完整表达式”(标准中使用的术语)可能不是表达式。 [intro.
我正在研究数字图像处理。当我尝试加载更高分辨率的图像时,我遇到了很多 OOM 问题。 我正在将这些启动参数与应用程序一起使用 -Xms10240m -Xmx10240m -XX:NewRatio=3
我为我的 java 应用程序配置了以下参数 -Xmx = 46g,-Xms = 46g,NewSize = 2g。 我们没有为 permgen 配置大小,但在 JCONSOLE 中它显示最大 perm
我正在尝试构建以下布局: +-----------------------------------+ | | +----------
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我已经多次看到这个问题被问到,但是当我尝试实现他们的解决方案时,它似乎不起作用。 我目前开始使用外部样式表涉足 HTML 和 CSS。 我创建了一个包含以下内容的容器(边框只是为了帮助我了解容器):
假设您有一个 (1) Intel/AMD x86-64 位 2 GHz 8 核处理器。 8 个内核中的每一个是否都以完整的 2 GHz 运行,或者每个内核是否以完整的 2 GHz 时钟的一部分运行(例
我想使用 RavenDb 4.0.0-beta-40018 查询一个包含动态属性的实体,但我不确定如何去做。 class Foo { public int Id { get; set; }
我的全文搜索索引有问题。我有一个字符字段大小为 30 的表。我在这个字段上创建了一个全文搜索索引,以便在这个不区分大小写的字段上进行快速搜索操作。现在,当我执行以下查询时:SELECT fieldna
如果我有一个 64 长度的 java 数组 i[],除了循环整个数组之外,是否有一种快速方法可以找出该数组中的每个位置是否“已满”?我正在编写一个黑白棋 AI,我需要知道整个数组是否已满。 最佳答案
stackoverflow 上有很多关于如何正确执行分页的问题,对于 Oracle,最流行的答案是这样的: select * from ( select row_.*, rownum rown
我有套接字应用程序,其代码片段如下。我已确保套接字在finally block 中关闭。我猜我昨天或前天刚刚进行了一次 Full GC。然后我通过jmap比较这次FGC之前和今天FGC之后的套接字实例
这里是我的 gc.log 的摘录: 2013-02-28T12:02:13.209+0100: 1486457.849: [GC 1486457.850: [ParNew 3483368K->9683
我有一个在一个 tomcat 实例上运行的 Java webapp。在高峰时段,Web 应用程序每秒提供大约 30 个页面,通常约为 15 个页面。 我的环境是: O/S: SUSE Linux En
我有一个包含一个日期时间列的表。我只需要返回最近 6 个月的行。这可以通过 WHERE CloseTime >= DATEADD(Month, DATEDIFF(Month, 0, DATEADD(m
如何获取 SVN 存储库的完整副本并将其导入到另一台服务器上? 最佳答案 您想要执行 svnadmin 转储。您可以通过 svnadmin help dump 或 reading the docs 获
当我使用 Wikipedia API 执行全文搜索时,我无法将搜索范围缩小到仅标题 (srwhat=title)。 所以在任何地方搜索时(默认) http://en.wikipedia.org/w/a
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
我想在数十亿个字符串中进行一般的子字符串搜索。该要求与一般全文搜索略有不同,因为我希望查询“ubst”也可以点击“substr”。 Lucene 或 Sphinx 是否能够做到这一点?如果没有,您认为
Sphinx 可以在一个句子中搜索单词。例如,我们有下一个文本: Вася молодец, съел огурец, т.к. проголодался. Такие дела. 如果我搜索 мол
我是一名优秀的程序员,十分优秀!