如何在Java中查看此GC的总内存使用情况

时间:2016-07-14 14:12:37

标签: java garbage-collection

我试图看看我应该为进程留出多少内存。这就是我启动应用程序的方式。

'-server -Xmx10G -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps'

所以,我给应用程序10G。但我想知道它真正使用了多少。那可能吗?我有这个垃圾收集器日志。

5997.472: [GC pause (young), 0.0195390 secs]
   [Parallel Time: 9.6 ms, GC Workers: 8]
      [GC Worker Start (ms): Min: 5997472.0, Avg: 5997476.1, Max: 5997480.9, Diff: 8.9]
      [Ext Root Scanning (ms): Min: 0.0, Avg: 2.7, Max: 6.4, Diff: 6.4, Sum: 21.3]
      [Update RS (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.5]
         [Processed Buffers: Min: 0, Avg: 4.6, Max: 13, Diff: 13, Sum: 37]
      [Scan RS (ms): Min: 0.3, Avg: 1.5, Max: 1.9, Diff: 1.6, Sum: 11.8]
      [Code Root Scanning (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 1.6]
      [Object Copy (ms): Min: 0.0, Avg: 0.3, Max: 0.8, Diff: 0.8, Sum: 2.5]
      [Termination (ms): Min: 0.0, Avg: 0.4, Max: 0.5, Diff: 0.5, Sum: 3.5]
      [GC Worker Other (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.7]
      [GC Worker Total (ms): Min: 0.4, Avg: 5.2, Max: 9.4, Diff: 9.1, Sum: 41.7]
      [GC Worker End (ms): Min: 5997481.3, Avg: 5997481.3, Max: 5997481.4, Diff: 0.2]
   [Code Root Fixup: 0.1 ms]
   [Code Root Migration: 0.6 ms]
   [Clear CT: 1.1 ms]
   [Other: 8.2 ms]
      [Choose CSet: 0.0 ms]
      [Ref Proc: 0.4 ms]
      [Ref Enq: 0.0 ms]
      [Free CSet: 7.7 ms]
   [Eden: 5433.0M(5433.0M)->0.0B(5433.0M) Survivors: 1024.0K->1024.0K Heap: 9008.4M(10192.0M)->3575.4M(10192.0M)]
 [Times: user=0.06 sys=0.01, real=0.02 secs]
6002.843: [GC pause (young), 0.0732310 secs]
   [Parallel Time: 34.1 ms, GC Workers: 8]
      [GC Worker Start (ms): Min: 6002843.5, Avg: 6002854.0, Max: 6002862.0, Diff: 18.5]
      [Ext Root Scanning (ms): Min: 0.0, Avg: 5.3, Max: 23.1, Diff: 23.1, Sum: 42.6]
      [Update RS (ms): Min: 0.0, Avg: 0.3, Max: 1.4, Diff: 1.4, Sum: 2.6]
         [Processed Buffers: Min: 0, Avg: 6.2, Max: 27, Diff: 27, Sum: 50]
      [Scan RS (ms): Min: 0.5, Avg: 2.5, Max: 5.1, Diff: 4.6, Sum: 20.0]
      [Code Root Scanning (ms): Min: 0.0, Avg: 0.2, Max: 0.5, Diff: 0.5, Sum: 1.8]
      [Object Copy (ms): Min: 0.0, Avg: 1.6, Max: 10.2, Diff: 10.2, Sum: 12.4]
      [Termination (ms): Min: 0.0, Avg: 6.5, Max: 8.7, Diff: 8.7, Sum: 51.9]
      [GC Worker Other (ms): Min: 0.0, Avg: 1.5, Max: 3.0, Diff: 2.9, Sum: 11.9]
      [GC Worker Total (ms): Min: 8.5, Avg: 17.9, Max: 29.8, Diff: 21.3, Sum: 143.2]
      [GC Worker End (ms): Min: 6002870.4, Avg: 6002871.9, Max: 6002873.3, Diff: 2.9]
   [Code Root Fixup: 0.1 ms]
   [Code Root Migration: 1.1 ms]
   [Clear CT: 2.4 ms]
   [Other: 35.6 ms]
      [Choose CSet: 0.0 ms]
      [Ref Proc: 18.4 ms]
      [Ref Enq: 0.0 ms]
      [Free CSet: 16.9 ms]
   [Eden: 5433.0M(5433.0M)->0.0B(5430.0M) Survivors: 1024.0K->1024.0K Heap: 9010.7M(10192.0M)->3577.9M(10192.0M)]
 [Times: user=0.13 sys=0.01, real=0.07 secs]
Heap
 garbage-first heap   total 10436608K, used 6181542K [0x0000000575a00000, 0x00000007f2a00000, 0x00000007f5a00000)
  region size 1024K, 2460 young (2519040K), 1 survivors (1024K)
 compacting perm gen  total 52224K, used 51927K [0x00000007f5a00000, 0x00000007f8d00000, 0x0000000800000000)
   the space 52224K,  99% used [0x00000007f5a00000, 0x00000007f8cb5e30, 0x00000007f8cb6000, 0x00000007f8d00000)
No shared spaces configured.

这是应用程序停止运行之前的最后一个日志(该过程已完成)。当我在机器上使用top命令时,我总是看到10G的过程,我猜这是Xmx选项的效果。但如果我知道它实际使用了多少,我可以调整并降低它。所以,我将有更多的空间用于其他流程。如果您想查看其他日志,请告诉我。

2 个答案:

答案 0 :(得分:1)

就在这里:total 10436608K, used 6181542K。所以到这一行的时候你的应用程序使用了大约6G的堆

答案 1 :(得分:1)

而不是尝试动态确定最小必要堆大小you can let the JVM yield memory back to the OS,而不是以略微降低的吞吐量为代价。

设置This is an example of the KEYWORD_ID/Replace_Command that is given as an input, KEYWORD_ID/Replace_Command replace command should be replaced 的严格限制是一个非常糟糕的主意。它会导致过多的垃圾收集,因为它会很快填满,或者当你的工作量变化时会直接导致OOME,并且它会暂时需要更多的内存。

您似乎也关心暂停时间,收集者可能会使用超出实时数据集的额外内存来满足这些目标。如果G1没有足够的备用容量同时完成其工作,则必须回退到完整的GC。