读懂parallel gc log

Java8 ,HotspotVM, 核心参数:

CommandLine flags:

text 复制代码
-XX:+AlwaysPreTouch
-XX:CompressedClassSpaceSize=528482304
-XX:ErrorFile=/app/logs/my-biz/hs_err_%p.log
-XX:GCLogFileSize=1048576000
-XX:+HeapDumpBeforeFullGC 【因为是测试环境,所以加了这个参数】
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/app/logs/my-biz
-XX:InitialHeapSize=17179869184
-XX:MaxHeapSize=17179869184
-XX:MaxMetaspaceSize=536870912
-XX:MetaspaceSize=268435456
-XX:NewRatio=1
-XX:NumberOfGCLogFiles=5
-XX:-OmitStackTraceInFastThrow
-XX:+PrintCommandLineFlags
-XX:+PrintFlagsFinal
-XX:+PrintGC
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintHeapAtGC
-XX:+UnlockDiagnosticVMOptions
-XX:+UseCompressedClassPointers
-XX:+UseCompressedOops
-XX:+UseGCLogFileRotation
-XX:+UseParallelGC
-XX:-UseAdaptiveSizePolicy 【这个参数没加】

应用在跑了一段时间后,gc log如下,这里主要是记录下备忘:

text 复制代码
2024-02-20T17:30:45.436+0800: 21056.921: Total time for which application threads were stopped: 0.0039479 seconds, Stopping threads took: 0.0004651 seconds

#第1097 次 gc (GCLocker Initiated GC,不过为啥也会引发垃圾回收呢?TODO);此时还没有fullgc 
{Heap before GC invocations=1097 (full 0):
 PSYoungGen      total 6738432K, used 6732547K [0x00000005e0800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 6044672K, 99% used [0x00000005e0800000,0x0000000751142610,0x0000000751700000)
  from space 693760K, 99% used [0x00000007b6280000,0x00000007e07fe630,0x00000007e0800000)
  to   space 1171968K, 0% used [0x0000000751700000,0x0000000751700000,0x0000000798f80000)
 ParOldGen       total 8388608K, used 4992341K [0x00000003e0800000, 0x00000005e0800000, 0x00000005e0800000)
  object space 8388608K, 59% used [0x00000003e0800000,0x00000005113556b0,0x00000005e0800000)
 Metaspace       used 139136K, capacity 151259K, committed 151424K, reserved 1183744K
  class space    used 15678K, capacity 17502K, committed 17536K, reserved 1048576K
2024-02-20T17:30:45.459+0800: 21056.945: [GC (GCLocker Initiated GC) [PSYoungGen: 6732547K->1171955K(7216640K)] 11724888K->7372510K(15605248K), 0.2131267 secs] [Times: user=6.32 sys=1.22, real=0.22 secs] 
Heap after GC invocations=1097 (full 0):
 PSYoungGen      total 7216640K, used 1171955K [0x00000005e0800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 6044672K, 0% used [0x00000005e0800000,0x00000005e0800000,0x0000000751700000)
  from space 1171968K, 99% used [0x0000000751700000,0x0000000798f7cf40,0x0000000798f80000)
  to   space 1171968K, 0% used [0x0000000798f80000,0x0000000798f80000,0x00000007e0800000)
 ParOldGen       total 8388608K, used 6200554K [0x00000003e0800000, 0x00000005e0800000, 0x00000005e0800000)
  object space 8388608K, 73% used [0x00000003e0800000,0x000000055af3a950,0x00000005e0800000)
 Metaspace       used 139136K, capacity 151259K, committed 151424K, reserved 1183744K
  class space    used 15678K, capacity 17502K, committed 17536K, reserved 1048576K
}


2024-02-20T17:30:45.673+0800: 21057.158: Total time for which application threads were stopped: 0.2279374 seconds, Stopping threads took: 0.0038452 seconds
2024-02-20T17:30:46.057+0800: 21057.542: Total time for which application threads were stopped: 0.0123185 seconds, Stopping threads took: 0.0025314 seconds
# 第1098次 gc (GC (Allocation Failure),此时也没有full gc 。【注意】新生代的大小发生了 变化!!!因为我们没有加【-XX:-UseAdaptiveSizePolicy】
{Heap before GC invocations=1098 (full 0):
 PSYoungGen      total 7216640K, used 7216627K [0x00000005e0800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 6044672K, 100% used [0x00000005e0800000,0x0000000751700000,0x0000000751700000)
  from space 1171968K, 99% used [0x0000000751700000,0x0000000798f7cf40,0x0000000798f80000)
  to   space 1171968K, 0% used [0x0000000798f80000,0x0000000798f80000,0x00000007e0800000)
 ParOldGen       total 8388608K, used 6440555K [0x00000003e0800000, 0x00000005e0800000, 0x00000005e0800000)
  object space 8388608K, 76% used [0x00000003e0800000,0x000000056999afd8,0x00000005e0800000)
 Metaspace       used 139141K, capacity 151323K, committed 151424K, reserved 1183744K
  class space    used 15678K, capacity 17502K, committed 17536K, reserved 1048576K
2024-02-20T17:30:46.712+0800: 21058.197: [GC (Allocation Failure) [PSYoungGen: 7216627K->1171953K(4494848K)] 13657183K->9195030K(12883456K), 0.1764428 secs] [Times: user=3.97 sys=2.57, real=0.17 secs] 
Heap after GC invocations=1098 (full 0):
 PSYoungGen      total 4494848K, used 1171953K [0x00000005e0800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 3322880K, 0% used [0x00000005e0800000,0x00000005e0800000,0x00000006ab500000)
  from space 1171968K, 99% used [0x0000000798f80000,0x00000007e07fc750,0x00000007e0800000)
  to   space 2532864K, 0% used [0x00000006ab500000,0x00000006ab500000,0x0000000745e80000)
 ParOldGen       total 8388608K, used 8023076K [0x00000003e0800000, 0x00000005e0800000, 0x00000005e0800000)
  object space 8388608K, 95% used [0x00000003e0800000,0x00000005ca309368,0x00000005e0800000)
 Metaspace       used 139141K, capacity 151323K, committed 151424K, reserved 1183744K
  class space    used 15678K, capacity 17502K, committed 17536K, reserved 1048576K
}

#第1099次gc 【Full GC (Ergonomics) ,这次是个fullgc了 ,花费了 690ms左右】
2024-02-20T17:30:46.888+0800: 21058.374: [Heap Dump (before full gc): , 0.0000775 secs]
{Heap before GC invocations=1099 (full 1):
 PSYoungGen      total 4494848K, used 1171953K [0x00000005e0800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 3322880K, 0% used [0x00000005e0800000,0x00000005e0800000,0x00000006ab500000)
  from space 1171968K, 99% used [0x0000000798f80000,0x00000007e07fc750,0x00000007e0800000)
  to   space 2532864K, 0% used [0x00000006ab500000,0x00000006ab500000,0x0000000745e80000)
 ParOldGen       total 8388608K, used 8023076K [0x00000003e0800000, 0x00000005e0800000, 0x00000005e0800000)
  object space 8388608K, 95% used [0x00000003e0800000,0x00000005ca309368,0x00000005e0800000)
 Metaspace       used 139141K, capacity 151323K, committed 151424K, reserved 1183744K
  class space    used 15678K, capacity 17502K, committed 17536K, reserved 1048576K
2024-02-20T17:30:46.889+0800: 21058.374: [Full GC (Ergonomics) [PSYoungGen: 1171953K->0K(4494848K)] [ParOldGen: 8023076K->2460629K(8388608K)] 9195030K->2460629K(12883456K), [Metaspace: 139141K->137506K(1183744K)], 0.6823041 secs] [Times: user=4.57 sys=6.16, real=0.69 secs] 
Heap after GC invocations=1099 (full 1):
 PSYoungGen      total 4494848K, used 0K [0x00000005e0800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 3322880K, 0% used [0x00000005e0800000,0x00000005e0800000,0x00000006ab500000)
  from space 1171968K, 0% used [0x0000000798f80000,0x0000000798f80000,0x00000007e0800000)
  to   space 2532864K, 0% used [0x00000006ab500000,0x00000006ab500000,0x0000000745e80000)
 ParOldGen       total 8388608K, used 2460629K [0x00000003e0800000, 0x00000005e0800000, 0x00000005e0800000)
  object space 8388608K, 29% used [0x00000003e0800000,0x0000000476af55e8,0x00000005e0800000)
 Metaspace       used 137506K, capacity 148613K, committed 151424K, reserved 1183744K
  class space    used 15423K, capacity 17043K, committed 17536K, reserved 1048576K
}

需要注意:有些监控工具比如prometheus,实际上把上述的Full GC (Ergonomics) 事件在监控上标记成了 Major GC (Ergonomics)

为啥呢?下面是gpt的回答:

text 复制代码
Q: 
I find that in some monitoring system, like `prometheus`(may be some others), `full gcs` may be labeled as `major gcs` ,why? 
A: 
In some monitoring systems, including Prometheus and others, the terms "full GCs" and "major GCs" may be used interchangeably or may both refer to the same type of garbage collection event. This can occur due to variations in terminology and terminology conventions across different systems and tools.

The terms "full GC" and "major GC" both generally refer to garbage collection events that involve collecting garbage from the entire heap, including both the young and old generations. These events typically occur when the JVM determines that a full heap cleanup is necessary, either due to 【high heap occupancy, fragmentation, or explicit garbage collection requests】.

While the terms may have slightly different origins or connotations, they are often used synonymously /sɪˈnɒnɪməsli, 同义地/ in practice to describe the same type of garbage collection event. As a result, monitoring systems may use either term interchangeably, depending on their specific naming conventions or terminology preferences.

It's worth noting that the choice of terminology may also depend on the specific JVM implementation, garbage collection algorithm, or documentation conventions followed by the developers of the monitoring system. Ultimately, regardless of the terminology used, the important aspect is to understand the nature and impact of garbage collection events on application performance and resource utilization

TODO: 更多的关于parallel的

Parallel GC 是java8的默认回收器(注意CMS+ParNew并不是)。

相关推荐
EnigmaCoder3 分钟前
蓝桥杯刷题周计划(第二周)
学习·算法·蓝桥杯
黑金IT7 分钟前
深入理解人脸特征向量及图片转换方法与开发架构
算法·架构
HP-Patience22 分钟前
决策树 vs 神经网络:何时使用?
神经网络·算法·决策树
AI很强24 分钟前
matlab常见的配图代码实现1
开发语言·算法·matlab
飞川00128 分钟前
🚀 力扣热题 78:子集(详细解析)
算法
FreemanGordon36 分钟前
Java volatile 关键字
java
北京_宏哥37 分钟前
《手把手教你》系列基础篇(九十三)-java+ selenium自动化测试-框架设计基础-POM设计模式实现-上篇(详解教程)
java·前端·selenium
北京_宏哥44 分钟前
《手把手教你》系列基础篇(九十二)-java+ selenium自动化测试-框架设计基础-POM设计模式简介(详解教程)
java·selenium·前端工程化
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧1 小时前
C语言_数据结构总结6:链式栈
c语言·开发语言·数据结构·算法·链表·visualstudio·visual studio
当归10241 小时前
微服务与消息队列RabbitMQ
java·微服务