当我使用G1GC时,为什么Scan RS需要花费很长时间

时间:2014-11-20 05:10:50

标签: java garbage-collection g1gc

我正在使用java1.7.0_67并运行我的应用程序:

 -Xms8g -Xmx8g -XX:PermSize=128M -XX:MaxPermSize=128M   -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:log/gc.log   -jar ***.jar

下面是我的gc日志:

3245.340: [GC pause (young), 0.9650490 secs]<br />

   [Parallel Time: 953.5 ms, GC Workers: 4]<br />
      [GC Worker Start (ms): Min: 3245340.8, Avg: 3245343.0, Max: 3245348.7, Diff: 7.9]<br />
      [Ext Root Scanning (ms): Min: 0.0, Avg: 4.8, Max: 7.2, Diff: 7.2, Sum: 19.1]<br />
      [Update RS (ms): Min: 7.9, Avg: 20.1, Max: 39.9, Diff: 32.0, Sum: 80.3]<br />
         [Processed Buffers: Min: 10, Avg: 19.5, Max: 35, Diff: 25, Sum: 78]<br />
      [Scan RS (ms): Min: 669.9, Avg: 690.4, Max: 702.4, Diff: 32.5, Sum: 2761.6]<br />
      [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]<br />
      [Object Copy (ms): Min: 235.3, Avg: 235.9, Max: 236.4, Diff: 1.0, Sum: 943.5]<br />
      [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]<br />
      [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]<br />
      [GC Worker Total (ms): Min: 945.5, Avg: 951.2, Max: 953.4, Diff: 7.9, Sum: 3804.6]<br />
      [GC Worker End (ms): Min: 3246294.2, Avg: 3246294.2, Max: 3246294.2, Diff: 0.0]<br />
   [Code Root Fixup: 0.1 ms]<br />
   [Code Root Migration: 0.0 ms]<br />
   [Clear CT: 0.4 ms]<br />
   [Other: 11.0 ms]<br />
      [Choose CSet: 0.0 ms]<br />
      [Ref Proc: 1.4 ms]<br />
      [Ref Enq: 0.0 ms]<br />
      [Free CSet: 1.7 ms]<br />
   [Eden: 356.0M(356.0M)->0.0B(356.0M) Survivors: 52.0M->52.0M Heap: 1682.0M(8192.0M)->1388.0M(8192.0M)]<br />
 [Times: user=3.74 sys=0.02, real=0.96 secs] <br />
3606.407: [GC pause (young), 0.5226400 secs]<br />
   [Parallel Time: 511.1 ms, GC Workers: 4]<br />
      [GC Worker Start (ms): Min: 3606407.5, Avg: 3606407.5, Max: 3606407.6, Diff: 0.0]<br />
      [Ext Root Scanning (ms): Min: 5.1, Avg: 5.2, Max: 5.2, Diff: 0.1, Sum: 20.7]<br />
      [Update RS (ms): Min: 7.5, Avg: 28.1, Max: 41.0, Diff: 33.6, Sum: 112.6]<br />
         [Processed Buffers: Min: 6, Avg: 18.8, Max: 51, Diff: 45, Sum: 75]<br />
      [Scan RS (ms): Min: 298.3, Avg: 311.2, Max: 331.7, Diff: 33.4, Sum: 1244.6]<br />
      [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.0, Sum: 0.1]<br />
      [Object Copy (ms): Min: 165.8, Avg: 166.0, Max: 166.4, Diff: 0.6, Sum: 664.1]<br />
      [Termination (ms): Min: 0.1, Avg: 0.5, Max: 0.6, Diff: 0.5, Sum: 1.9]<br />
      [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]<br />
      [GC Worker Total (ms): Min: 511.0, Avg: 511.0, Max: 511.0, Diff: 0.0, Sum: 2044.1]<br />
      [GC Worker End (ms): Min: 3606918.6, Avg: 3606918.6, Max: 3606918.6, Diff: 0.0]<br />
   [Code Root Fixup: 0.3 ms]<br />
   [Code Root Migration: 0.0 ms]<br />
   [Clear CT: 0.5 ms]<br />
   [Other: 10.7 ms]<br />
      [Choose CSet: 0.0 ms]<br />
      [Ref Proc: 2.5 ms]<br />
      [Ref Enq: 0.1 ms]<br />
      [Free CSet: 0.9 ms]<br />
   [Eden: 356.0M(356.0M)->0.0B(396.0M) Survivors: 52.0M->12.0M Heap: 1744.0M(8192.0M)->1406.0M(8192.0M)]<br />
 [Times: user=2.00 sys=0.01, real=0.52 secs] <br />

扫描RS花费的时间太长了......

我该如何修改它?

1 个答案:

答案 0 :(得分:0)

如果您关心暂停时间,可以尝试并发收集器-XX:+ UseConcMarkSweepGC。对于你的堆大小和核心数量,我预计会在50-100ms的范围内暂停。