Minor GC 和 Full GC 同时进行?

Minor GC and full GC at the same time?

这是一段显示完整 CMS GC 事件的 GC 日志:

2016-12-29T22:44:34.741-0500: 27572.982: [GC (CMS Initial Mark) [1 CMS-initial-mark: 2508212K(23068672K)] 2931097K(26843584K), 0.0213349 secs] [Times: user=0.22 sys=0.00, real=0.02 secs] 
2016-12-29T22:44:34.763-0500: 27573.004: [CMS-concurrent-mark-start]
2016-12-29T22:44:36.013-0500: 27574.254: [CMS-concurrent-mark: 0.208/1.250 secs] [Times: user=3.07 sys=0.10, real=1.25 secs] 
2016-12-29T22:44:36.014-0500: 27574.255: [CMS-concurrent-preclean-start]
2016-12-29T22:44:36.061-0500: 27574.303: [CMS-concurrent-preclean: 0.047/0.048 secs] [Times: user=0.12 sys=0.00, real=0.05 secs] 
2016-12-29T22:44:36.062-0500: 27574.303: [CMS-concurrent-abortable-preclean-start]
 CMS: abort preclean due to time 2016-12-29T22:44:41.339-0500: 27579.580: [CMS-concurrent-abortable-preclean: 4.084/5.277 secs] [Times: user=9.53 sys=0.46, real=5.27 secs] 
2016-12-29T22:44:41.356-0500: 27579.598: [GC (CMS Final Remark) [YG occupancy: 3509179 K (3774912 K)]2016-12-29T22:44:41.357-0500: 27579.598: [Rescan (parallel) , 0.0816014 secs]2016-12-29T22:44:41.438-0500: 27579.680: [weak refs processing, 0.0000347 secs]2016-12-29T22:44:41.438-0500: 27579.680: [class unloading, 0.0292451 secs]2016-12-29T22:44:41.468-0500: 27579.709: [scrub symbol table, 0.0069857 secs]2016-12-29T22:44:41.475-0500: 27579.716: [scrub string table, 0.0010933 secs][1 CMS-remark: 2508212K(23068672K)] 6017391K(26843584K), 0.1194737 secs] [Times: user=2.18 sys=0.00, real=0.12 secs] 
2016-12-29T22:44:41.477-0500: 27579.718: [CMS-concurrent-sweep-start]
2016-12-29T22:44:41.618-0500: 27579.860: [GC (Allocation Failure) 2016-12-29T22:44:41.619-0500: 27579.860: [ParNew: 3579431K->419392K(3774912K), 5.7752364 secs] 6080306K->3302237K(26843584K), 5.7769753 secs] [Times: user=4.70 sys=8.50, real=5.78 secs] 
2016-12-29T22:44:47.698-0500: 27585.940: [CMS-concurrent-sweep: 0.230/6.221 secs] [Times: user=5.76 sys=8.55, real=6.22 secs] 
2016-12-29T22:44:47.699-0500: 27585.940: [CMS-concurrent-reset-start]
2016-12-29T22:44:47.717-0500: 27585.958: [GC (System.gc()) 2016-12-29T22:44:47.718-0500: 27585.959: [ParNew: 527384K->155025K(3774912K), 0.7351766 secs] 3405551K->3441841K(26843584K), 0.7366514 secs] [Times: user=5.61 sys=1.44, real=0.74 secs] 
2016-12-29T22:44:48.503-0500: 27586.744: [CMS-concurrent-reset: 0.049/0.804 secs] [Times: user=5.81 sys=1.45, real=0.81 secs] 

当 CMS 处于 运行:

时似乎发生了次要的 GC 事件
2016-12-29T22:44:41.618-0500: 27579.860: [GC (Allocation Failure) 2016-12-29T22:44:41.619-0500: 27579.860: [ParNew: 3579431K->419392K(3774912K), 5.7752364 secs] 6080306K->3302237K(26843584K), 5.7769753 secs] [Times: user=4.70 sys=8.50, real=5.78 secs] 

可以吗? minor GC 会阻塞 full GC 吗?

这可以解释我们看到的非常高的系统时间吗? (系统=8.55 秒,系统=8.50 秒)

在您的情况下,使用的 GC 算法是:-

Parallel New for Young + Concurrent Mark and Sweep (CMS) for the Old Generation

在 CMS 运行ning 期间似乎发生了次要的 GC 事件,可以吗?
是的,ParNew 和 CMS 可以 运行 并行。

minor GC会阻塞full GC吗?
是的,并发 CMS 集合是由 ParNew 次要集合 "interrupted"。 新生代的收集可以在并发收集老年代的任何时候发生。在这种情况下,主要收集将与次要 GC 事件交错

这可以解释我们看到的非常高的系统时间吗?
您需要检查 GC 中 Stop-the-world 事件的频率和持续时间。

  1. CMS初始标记
  2. CMS 最后评论
  3. ParNew

通过查看您的日志,我可以看出您的次要 GC (ParNew) 花费了太多时间才能完成。
5.7752364 秒:垃圾收集器标记和复制年轻一代中的活动对象所花费的时间+与 ConcurrentMarkSweep 收集器的通信开销

很好 reference Java GC,值得一读。

当然,年轻代回收可能发生在旧代回收期间。通常这不是一个大问题,但在 CMS 注释阶段紧随新生代收集的情况下(或其他方式,因此两者都是 stop-the-world 暂停)它可能会损害性能。 CMS 将通过计算下一次年轻回收发生的时间来尝试避免这种情况,但这只是理论上的。

如果Young GC运行在CMS阶段之间是完全可以的。在 CMS initial mark 或 CMS remark 之前进行年轻代回收甚至可以减少 major GC 的 stop-the-world 停顿。

什么是 NOT 正常情况是在执行 GC 时 sys 时间 (CPU 在内核中花费的时间)。这通常不应该发生,因为垃圾收集主要是用户 space 的工作。

检查topperf等,找出导致系统时间过长的原因。这通常与内存问题有关:交换或透明大页面碎片整理。