读懂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并不是)。

相关推荐
.生产的驴11 分钟前
SpringBoot 封装统一API返回格式对象 标准化开发 请求封装 统一格式处理
java·数据库·spring boot·后端·spring·eclipse·maven
猿周LV19 分钟前
JMeter 安装及使用 [软件测试工具]
java·测试工具·jmeter·单元测试·压力测试
知来者逆21 分钟前
计算机视觉——速度与精度的完美结合的实时目标检测算法RF-DETR详解
图像处理·人工智能·深度学习·算法·目标检测·计算机视觉·rf-detr
晨集21 分钟前
Uni-App 多端电子合同开源项目介绍
java·spring boot·uni-app·电子合同
时间之城23 分钟前
笔记:记一次使用EasyExcel重写convertToExcelData方法无法读取@ExcelDictFormat注解的问题(已解决)
java·spring boot·笔记·spring·excel
阿让啊25 分钟前
C语言中操作字节的某一位
c语言·开发语言·数据结构·单片机·算法
এ᭄画画的北北26 分钟前
力扣-160.相交链表
算法·leetcode·链表
椰羊~王小美30 分钟前
LeetCode -- Flora -- edit 2025-04-25
java·开发语言
凯酱38 分钟前
MyBatis-Plus分页插件的使用
java·tomcat·mybatis
程序员总部1 小时前
如何在IDEA中高效使用Test注解进行单元测试?
java·单元测试·intellij-idea