垃圾收集需要很长时间,有时

时间:2018-04-16 12:36:00

标签: garbage-collection apache-kafka garbage g1gc

在我们的kafka代理设置中,GC平均需要20毫秒,但随机增加到1-2秒。极端情况持续9秒。频率相当随机。平均每天发生15次。我尝试过使用GCEasy,但没有给出任何见解。我的内存使用率是20%,但是虽然内存可用,但进程仍然使用swap。感谢有关如何最小化的任何输入

JVM选择:

-Xmx3G -Xms1G -server -XX:MetaspaceSize=96m -XX:+UseG1GC -
XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=50 -
XX:G1HeapRegionSize=16M -XX:MinMetaspaceFreeRatio=50 -
XX:MaxMetaspaceFreeRatio=80

GC日志:

2018-04-15T18:22:26.526+0530: 529212.538: [GC pause (G1 Evacuation Pause) (young), 9.6174677 secs]
       [Parallel Time: 9422.7 ms, GC Workers: 10]
          [GC Worker Start (ms): Min: 529212702.8, Avg: 529212736.2, Max: 529212778.8, Diff: 76.1]
          [Ext Root Scanning (ms): Min: 117.8, Avg: 228.8, Max: 320.4, Diff: 202.5, Sum: 2287.9]
          [Update RS (ms): Min: 83.7, Avg: 134.0, Max: 203.6, Diff: 119.9, Sum: 1339.8]
             [Processed Buffers: Min: 1, Avg: 5.3, Max: 11, Diff: 10, Sum: 53]
          [Scan RS (ms): Min: 390.7, Avg: 449.4, Max: 498.2, Diff: 107.6, Sum: 4493.6]
          [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
          [Object Copy (ms): Min: 8438.7, Avg: 8496.9, Max: 8532.1, Diff: 93.3, Sum: 84969.4]
          [Termination (ms): Min: 0.0, Avg: 18.8, Max: 21.5, Diff: 21.5, Sum: 187.9]
             [Termination Attempts: Min: 1, Avg: 3.8, Max: 9, Diff: 8, Sum: 38]
          [GC Worker Other (ms): Min: 2.5, Avg: 27.3, Max: 91.3, Diff: 88.8, Sum: 273.1]
          [GC Worker Total (ms): Min: 9312.4, Avg: 9355.2, Max: 9388.3, Diff: 75.9, Sum: 93551.7]
          [GC Worker End (ms): Min: 529222091.1, Avg: 529222091.3, Max: 529222091.7, Diff: 0.6]
       [Code Root Fixup: 1.9 ms]
       [Code Root Purge: 0.0 ms]
       [Clear CT: 12.1 ms]
       [Other: 180.8 ms]
          [Choose CSet: 0.0 ms]
          [Ref Proc: 18.0 ms]
          [Ref Enq: 0.0 ms]
          [Redirty Cards: 13.4 ms]
          [Humongous Register: 11.8 ms]
          [Humongous Reclaim: 0.2 ms]
          [Free CSet: 5.1 ms]
       [Eden: 768.0M(128.0M)->0.0B(128.0M) Survivors: 16.0M->16.0M Heap: 1775.9M(3072.0M)->1007.3M(3072.0M)]
     [Times: user=10.00 sys=15.22, real=9.63 secs]

1 个答案:

答案 0 :(得分:0)

您的日志显示,每个区域每个gc线程的个人时间很短(100毫秒),但整个垃圾收集的总时间很长,对象复制阶段占用了大部分时间。

[Parallel Time: 9422.7 ms, GC Workers: 10]
          [GC Worker Start (ms): Min: 529212702.8, Avg: 529212736.2, Max: 529212778.8, Diff: 76.1]
          [Ext Root Scanning (ms): Min: 117.8, Avg: 228.8, Max: 320.4, Diff: 202.5, **Sum: 2287.9**]
          [Update RS (ms): Min: 83.7, Avg: 134.0, Max: 203.6, Diff: 119.9, **Sum: 1339.8**]
             [Processed Buffers: Min: 1, Avg: 5.3, Max: 11, Diff: 10, Sum: 53]
          [Scan RS (ms): Min: 390.7, Avg: 449.4, Max: 498.2, Diff: 107.6, **Sum: 4493.6**]
          [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
          **[Object Copy (ms): Min: 8438.7, Avg: 8496.9, Max: 8532.1, Diff: 93.3, Sum: 84969.4]**
          [Termination (ms): Min: 0.0, Avg: 18.8, Max: 21.5, Diff: 21.5, Sum: 187.9]
             [Termination Attempts: Min: 1, Avg: 3.8, Max: 9, Diff: 8, Sum: 38]
          [GC Worker Other (ms): Min: 2.5, Avg: 27.3, Max: 91.3, Diff: 88.8, Sum: 273.1]
          [GC Worker Total (ms): Min: 9312.4, Avg: 9355.2, Max: 9388.3, Diff: 75.9, Sum: 93551.7]
          [GC Worker End (ms): Min: 529222091.1, Avg: 529222091.3, Max: 529222091.7, Diff: 0.6]

将平均收集时间提高到更高的值。我怀疑这种行为的原因很少,

  1. XX:G1HeapRegionSize = 16M - 应该考虑可用的核心数,允许的gc线程/工作人员等来设置此参数。最好让JVM为您选择该值,除非您非常确定。

  2. 对象复制阶段需要花费时间将对象从幸存者空间复制到下一个空格。看起来您在短时间内创建了大量新对象。如果可能,您可以尝试增加堆大小,尤其是年轻代。这将减少从一个幸存者空间到另一个幸存者空间的对象复制频率。

  3. 这也可能因为交换但不确定这些日志而发生。禁用交换是值得一试的,是罪魁祸首。

  4. 如果你在cpu方面有更多的处理能力,那么尝试增加gc工作线程的数量。