java – 当旧的gen为’空’时,JVM运行旧的垃圾收集

我有一个运行的Clojure应用程序,它有大量的内存流失用于大堆分配,所以它已经适当地设置了JVM opts:

-Xmx13g -XX:+UseConcMarkSweepGC -XX:NewSize=10G -server -XX:+UseParNewGC

这大部分时间都可以工作,并且避免了新的gen溢出到旧版本的问题(有时仍然会让它成为幸存者,但并非总是如此),但有时候我们会看到如图所示的情况,即JVM运行CMS /旧版垃圾收集当新一代充满时真的很难.但是,我的理解是,这应该由新一代垃圾收集器处理.

《java – 当旧的gen为’空’时,JVM运行旧的垃圾收集》

两个问题.为什么旧的垃圾收集器运行时,旧的几乎是空的,但新的gen有东西?我是否可以进行任何进一步调整以减少GC不可避免地导致的暂停/减速?

ETA:在OpenJDK 8上运行.

ETA 2:GC日志:https://gist.github.com/gworley3/6abb9ab52320c6cbd508

最佳答案 简答:

CMS没有时间花费太多时间扫描近10GB的Young Gen.您可以通过添加选项来防止CMS收集器不必要地运行:

-XX:UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction =< K>

其中K是占领的旧Gen空间的任意分数.

答案很长:

参考Oracle CMS Documentation

The CMS collector pauses an application twice during a concurrent collection cycle. The first pause is to mark as live the objects directly reachable from the roots (for example, object references from application thread stacks and registers, static objects and so on) and from elsewhere in the heap (for example, the young generation). This first pause is referred to as the initial mark pause. The second pause comes at the end of the concurrent tracing phase and finds objects that were missed by the concurrent tracing due to updates by the application threads of references in an object after the CMS collector had finished tracing that object. This second pause is referred to as the remark pause.

CMS正在进行两次世界各地的停顿,每次扫描Young Gen进行标记.查看日志的前三行,您可以看到初始标记在ParNew之前需要5秒,之后需要0.25秒.这句话看到了类似的时间减少.

<190>1 2015-12-18T08:44:54.194216+00:00 host app web.1 - [GC[YG occupancy: 489826 K (9437184 K)][Rescan (parallel) , 0.2520950 secs][weak refs processing, 0.0000180 secs][scrub string table, 0.0008190 secs] [1 CMS-remark: 64504K(107240K)] 554330K(9544424K), 0.2530410 secs] [Times: user=1.95 sys=0.02, real=0.25 secs]

<190>1 2015-12-18T08:44:49.937257+00:00 host app web.1 - [GC[ParNew:   8418004K->93508K(9437184K), 0.0488580 secs] 8482343K->158013K(9544424K), 0.0489980 secs] [Times: user=0.33 sys=0.00, real=0.05 secs]

<190>1 2015-12-18T08:44:48.651086+00:00 host app web.1 - [GC [1 CMS-initial-mark: 64339K(107240K)] 7800216K(9544424K), 5.0756660 secs] [Times: user=5.08 sys=0.00, real=5.08 secs]

在每个CMS循环后,您的旧Gen空间几乎不会减少,因此开销当然不值得.减少CMS循环的频率将是一种可能的解决方案.

点赞