简体   繁体   English

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

[英]How to see the total memory usage of this GC in Java

I'm trying to see how much memory I should give to a process. 我正在尝试查看应为进程分配多少内存。 This is how I start the application. 这就是我启动应用程序的方式。

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

So, I'm giving the application 10G. 所以,我给应用程序10G。 But I would like to know how much it really uses. 但是我想知道它真正使用了多少。 Is that possible? 那可能吗? I have this Garbage Collector log. 我有此垃圾收集器日志。

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.

That's the last log before the application stop running (The process is done). 那是应用程序停止运行之前的最后一个日志(该过程已完成)。 When I use top command on the machine I always see 10G for the process I guess that's the effect of Xmx option. 当我在机器上使用top命令时,我总是看到10G的进程,我猜这就是Xmx选项的效果。 But if I know how much it actually uses I can adjust and lower it down. 但是,如果我知道它实际使用了多少,则可以调整并降低它。 So, I'll have more room for other processes. 因此,我将为其他进程留出更多空间。 Please let me know if any other log you want to see. 如果您要查看其他日志,请告诉我。

It is right here: total 10436608K, used 6181542K . 就在这里: total 10436608K, used 6181542K So by the time of this line your application used around 6G of heap 因此,在此行的时候,您的应用程序使用了大约6G的堆

Instead of attempting to determine the minimum necessary heap size you can let the JVM yield memory back to the OS dynamically, possibly at the expense of a little reduced throughput. 不必尝试确定最小的必需堆大小, 您可以让JVM动态地将内存释放回OS ,这可能会以稍微降低吞吐量为代价。

Setting a tight limit of heap size ≈ live data set is a very bad idea. heap size ≈ live data set设置一个严格的限制heap size ≈ live data set是一个非常糟糕的主意。 It will either cause excessive garbage collections because it will just fill up very quickly or it will outright lead to OOMEs when your workload varies and it momentarily needs some more memory. 它可能会导致过多的垃圾回收,因为它将很快填满,或者当您的工作负载变化并且暂时需要更多内存时,将直接导致OOME。

You also seem to care about pause times, the collectors may use extra memory beyond the live data set to meet those goals. 您似乎还关心暂停时间,收集器可能会使用超出实时数据集的额外内存来实现这些目标。 If there's not enough spare capacity for G1 to do its work concurrently it will have to fall back to a full GC. 如果没有足够的备用容量来同时执行G​​1的工作,则必须退回到完整的GC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM