高效码农

Java GC日志解析

GC样例:

[GC (Allocation Failure) [DefNew: 8133K->645K(9216K), 0.0039312 secs] 8133K->6789K(29696K), 0.0039751 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [DefNew: 8028K->332K(9216K), 0.0023424 secs] 14172K->9156K(29696K), 0.0023701 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [DefNew: 6610K->331K(9216K), 0.0031335 secs] 15435K->15300K(29696K), 0.0031569 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [Tenured: 14968K->11203K(20480K), 0.0035525 secs] 17348K->11203K(29696K), [Metaspace: 3771K->3771K(1056768K)], 0.0036041 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [DefNew: 6451K->0K(9216K), 0.0015189 secs] 17654K->17347K(29696K), 0.0015472 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [DefNew: 6292K->6292K(9216K), 0.0000119 secs][Tenured: 17347K->3010K(20480K), 0.0025006 secs] 23639K->3010K(29696K), [Metaspace: 3771K->3771K(1056768K)], 0.0025664 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [DefNew: 6277K->0K(9216K), 0.0009455 secs] 9288K->9154K(29696K), 0.0009618 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 def new generation   total 9216K, used 2212K [0x00000000fe200000, 0x00000000fec00000, 0x00000000fec00000)
  eden space 8192K,  27% used [0x00000000fe200000, 0x00000000fe4290e0, 0x00000000fea00000)
  from space 1024K,   0% used [0x00000000feb00000, 0x00000000feb00000, 0x00000000fec00000)
  to   space 1024K,   0% used [0x00000000fea00000, 0x00000000fea00000, 0x00000000feb00000)
 tenured generation   total 20480K, used 9154K [0x00000000fec00000, 0x0000000100000000, 0x0000000100000000)
   the space 20480K,  44% used [0x00000000fec00000, 0x00000000ff4f0b40, 0x00000000ff4f0c00, 0x0000000100000000)
 Metaspace       used 3777K, capacity 4604K, committed 4864K, reserved 1056768K
  class space    used 418K, capacity 428K, committed 512K, reserved 1048576K

解析GC日志:

解析GC日志主要是为了了解垃圾收集器在Java应用程序运行期间的行为,帮助我们诊断和优化内存使用情况。下面是对你提供的GC日志的逐步分析:

1. GC日志格式

每一条GC日志包括几个重要的部分:

2. 年轻代GC事件

[GC (Allocation Failure) [DefNew: 8133K->645K(9216K), 0.0039312 secs] 8133K->6789K(29696K), 0.0039751 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

类似的还有下面几条年轻代GC事件,可以看到年轻代GC事件频繁发生,通常在几毫秒内完成:

[GC (Allocation Failure) [DefNew: 8028K->332K(9216K), 0.0023424 secs] 14172K->9156K(29696K), 0.0023701 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 6610K->331K(9216K), 0.0031335 secs] 15435K->15300K(29696K), 0.0031569 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

3. Full GC事件

[Full GC (System.gc()) [Tenured: 14968K->11203K(20480K), 0.0035525 secs] 17348K->11203K(29696K), [Metaspace: 3771K->3771K(1056768K)], 0.0036041 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

4. 堆信息

Heap
 def new generation   total 9216K, used 2212K [0x00000000fe200000, 0x00000000fec00000, 0x00000000fec00000)
  eden space 8192K,  27% used [0x00000000fe200000, 0x00000000fe4290e0, 0x00000000fea00000)
  from space 1024K,   0% used [0x00000000feb00000, 0x00000000feb00000, 0x00000000fec00000)
  to   space 1024K,   0% used [0x00000000fea00000, 0x00000000fea00000, 0x00000000feb00000)
 tenured generation   total 20480K, used 9154K [0x00000000fec00000, 0x0000000100000000, 0x0000000100000000)
   the space 20480K,  44% used [0x00000000fec00000, 0x00000000ff4f0b40, 0x00000000ff4f0c00, 0x0000000100000000)
 Metaspace       used 3777K, capacity 4604K, committed 4864K, reserved 1056768K
  class space    used 418K, capacity 428K, committed 512K, reserved 1048576K

总结

通过分析GC日志,我们可以得到以下结论:

通过持续监控GC日志并进行相应调整,可以有效优化Java应用程序的性能和稳定性。

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »