Detailed analysis and configuration of JVM GC log (1)

JVM GC log parameters

Case:
2021-03-25T13:00:41.631+0800: 4.013: [GC (Allocation Failure) [PSYoungGen: 419840K->20541K(472064K)] 419840K->20573K(996352K), 0.0118345 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]

The details are as follows:

  • 2021-03-25T13:00:41.631+0800: The time point when GC occurs.
  • 4.013: The GC that occurred after how long the system has been running, in seconds, here is a GC that has occurred after the system has been running for 4.013 seconds.
  • GC (Allocation Failure): Explains the reason for triggering GC, here refers to the GC caused by the failure of object allocation.
  • PSYoungGen: Refers to the garbage collection of the young generation that is triggered, using the Parallel Scavenge garbage collector.
  • 419840K->20541K: A GC was performed on the young generation. Before the GC, the young generation used 419840K. After the GC, 20541K objects survived.
  • (472064K): The available space for the young generation is 472064K, which is 461M. Why is it 461M? Because the size of the young generation is 512M, the Eden area occupies 409.6M, and the two Survivor areas each occupy 51.2M, the available space for the young generation is the size of Eden+1 Survivor, which is 460.8M, which is about 461M.
  • 419840K->20573K: Before GC, the entire heap memory used 419840K, and after GC, the heap memory used 20573K.
  • (996352K): The size of the entire heap is 996352K, which is 973M, which is actually 461M in the young generation + 512M in the old generation
  • 0.0118345 secs: the time spent in this GC
  • Times: user=0.00 sys=0.00, real=0.01 secs: the time spent in this GC
Heap
 PSYoungGen      total 472064K, used 406352K [0x00000000e0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 419840K, 93% used [0x00000000e0000000,0x00000000f7f00528,0x00000000f9a00000)
  from space 52224K, 27% used [0x00000000f9a00000,0x00000000fa7d3d70,0x00000000fcd00000)
  to   space 52224K, 0% used [0x00000000fcd00000,0x00000000fcd00000,0x0000000100000000)
 ParOldGen       total 524288K, used 189923K [0x00000000c0000000, 0x00000000e0000000, 0x00000000e0000000)
  object space 524288K, 36% used [0x00000000c0000000,0x00000000cb978d08,0x00000000e0000000)
 Metaspace       used 111852K, capacity 117676K, committed 117888K, reserved 1153024K
  class space    used 13876K, capacity 14914K, committed 14976K, reserved 1048576K

The details are as follows:

  • PSYoungGen total 472064K, used 406352K: Refers to the young generation responsible for the Parallel Scavenge collector has a total of 472064K (461M) of memory, and currently uses 406352K (396.8M).
  • eden space 419840K, 93% used: The space in the Eden area is 419840K (410M), and 93% has been used.
  • from space 52224K, 27% used: The space in the From Survivor area is 52224K (51M), and 27% has been used.
  • to space 52224K, 0% used: The space in the To Survivor area is 52224K (51M). When 0% is used, it is completely free.
  • ParOldGen total 524288K, used 189923K: Refers to a total of 524288K (512M) in the old generation that the Parallel Old collector is responsible for, and currently uses 189923K (185.4M).
  • object space 524288K, 36% used: The total size of the old space is 524288K (512M), 36% used.
  • Metaspace & class space: Metaspace metadata space and class space, total capacity, used memory, etc.
    Insert picture description here
-XX:+PrintGC (simple mode)
12.097: [GC (Allocation Failure)  419840K->18067K(996352K), 0.0197196 secs]
30.677: [Full GC 243120K->241951K(629760K), 1.5589690 secs]

This parameter just turns on the simple log mode, and prints a line of information for each Young Generation (Young Generation) GC and each Full GC.

First is the GC type (GC or Full GC), then the GC reason (Allocation Failure: Insufficient allocated object space leads to the new generation GC), and then the used heap space before and after the GC, and the current heap in the brackets Capacity, and finally the time (in seconds) of this GC.

The first line means that the used heap space of the new generation GC is reduced from 419840K to 18067K, the current heap capacity is 996352K, and the GC duration is 0.01197196 seconds.

The simple mode GC log format has nothing to do with the GC algorithm. The log does not provide much information, and it is impossible to determine from the log whether the GC has moved some objects from Young Generation to Old Generation. So detailed mode GC is more useful.

-XX:PrintGCDetails (detailed mode)

Using this command is to turn on the detailed GC log mode. In this mode, the log format is related to the GC algorithm used.

6.609: [GC (Allocation Failure) [PSYoungGen: 419840K->17473K(472064K)] 419840K->17561K(996352K), 0.0175394 secs] [Times: user=0.13 sys=0.00, real=0.02 secs] 
12.399: [GC (Allocation Failure) [PSYoungGen: 437313K->32044K(472064K)] 437401K->32156K(996352K), 0.0302068 secs] [Times: user=0.11 sys=0.00, real=0.03 secs] 
[Full GC
    [PSYoungGen: 10752K->9707K(142848K)]
    [ParOldGen: 232384K->232244K(485888K)] 243136K->241951K(628736K)
    [PSPermGen: 3162K->3161K(21504K)], 1.5265450 secs
]

It can be easily found that this is a GC in Young Generation, which reduces the used heap space of the young generation from 419840K to 17473K, and the available space of the young generation is 472064K. The entire heap before GC is used 419840K, and the entire heap is used after GC. At 17561K, the size of the entire heap is 996352K (new generation + old generation), which takes 0.0175394 seconds, and the garbage collector used is PS (Parallel Scavenge).

Times contains the CPU time information used by the GC (user+sys=0.13s time), which is the time used by the user space and system space of the operating system respectively, and the real time of GC running (real=0.02 secs, 0.02 is an approximate value), if the CPU time (0.13s) is significantly more than the real (real=0.02) time, we can draw the conclusion: GC uses multi-threaded operation, so the CPU time is the CPU time spent by all GC threads Sum.

Full GC is similar. Full GC can also be triggered by a displayed request, which can be through an application or an external JVM interface, so that the triggered GC can be easily distinguished in the log, because the output log is "Full GC (System) ", instead of "Full GC".

For the Serial garbage collector, the detailed GC log is very similar to the Throughput garbage collector. The only difference is that different generation logs may use different GC algorithms (for example: old generation logs may start with Tenured instead of ParOldGen). Using the garbage collector as the beginning of a line of log can facilitate us to judge the GC settings of the JVM from the log.

For the CMS garbage collector, the detailed log of the young generation is also very similar to the Throughput garbage collector, but the log of the old generation is not. For the CMS garbage collector, the GC in the old generation runs simultaneously with the application in different time slices. The GC log is naturally different from the Full GC log. And the logs at different time slices are mixed with the GC logs of the young generation during this period. But after understanding the basic elements of the GC log introduced above, it is not difficult to understand the logs in different time slices. Just pay special attention when interpreting the GC running time. Since most of the GC in the time slice runs at the same time as the application, it does not necessarily mean that the GC lasts longer than that of the exclusive GC. something wrong.

As we learned in Section 7, Full GC may occur even if the CMS garbage collector does not complete a CMS cycle. If a GC occurs, the log will contain the reason for triggering Full GC, such as the well-known "concurrent mode failure".

-XX:+PrintGCTimeStamps和-XX:+PrintGCDateStamps

Use -XX: PrintGCTimeStamps to add the actual and date to the GC log, indicating that the timestamp from the start of the JVM to the present will be added to each line.

6.195: [GC (Allocation Failure) [PSYoungGen: 419840K->17894K(472064K)] 419840K->17982K(996352K), 0.0213569 secs] [Times: user=0.00 sys=0.03, real=0.02 secs] 

If -XX:PrintGCDateStamps is specified, the absolute date and time are added to each line.

2021-03-31T13:58:47.268+0800: 6.963: [GC (Allocation Failure) [PSYoungGen: 419840K->16662K(472064K)] 419840K->16750K(996352K), 0.0325293 secs] [Times: user=0.08 sys=0.02, real=0.03 secs] 

If necessary, you can use both parameters at the same time. It is recommended to use these two parameters at the same time, because it is helpful when correlating GC logs from different sources.

-Xloggc

The default GC log is output to the terminal, and -Xloggc:./gc.log specifies the output to the specified file. Please note that this parameter implicitly sets the parameters -XX:+PrintGC and -XX:+PrintGCTimeStamps, but in order to prevent If there are any changes in the new version of the JVM, it is recommended to set these parameters displayed.

Manageable JVM parameters, a question that is often discussed is whether the GC log in the production environment should be turned on, because the overhead that it generates is usually very limited, so I suggest that it needs to be turned on, but it is not necessarily necessary when starting the JVM Specify GC log parameters.

HotSpot JVM has a special type of parameters called manageable parameters. For these parameters, their values ​​can be modified at runtime. All the parameters discussed here and the parameters beginning with "PrintGC" are all manageable parameters. In this way, we can turn on or off the GC log at any time. For example, we can use the jinfo tool that comes with the JDK to set these parameters, or call the setVMOption method of HotSpotDiagnostic MXBean through the JMX client to set these parameters. For example: for PrintGC setting, parameter 1: PrintGC, parameter 2: true. Print the log to set up successfully.

-XX:+PrintGCApplicationConcurrentTime
2021-03-31T15:14:11.961+0800: 6.454: Application time: 0.1916132 seconds
2021-03-31T15:14:11.961+0800: 6.454: [GC (Allocation Failure) [PSYoungGen: 419840K->16530K(472064K)] 419840K->16618K(996352K), 0.0182229 secs] [Times: user=0.13 sys=0.00, real=0.02 secs] 

Print the uninterrupted execution time of the program before each garbage collection.

-XX:+PrintGCApplicationStoppedTime
2021-03-31T15:17:27.106+0800: 0.408: Application time: 0.0001266 seconds
2021-03-31T15:17:27.106+0800: 0.408: Total time for which application threads were stopped: 0.0000742 seconds, Stopping threads took: 0.0000398 seconds

Print the pause time of the program during garbage collection, can be mixed with the above

-XX:PrintHeapAtGC

Print detailed stack information before and after GC

{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 472064K, used 419840K [0x00000000e0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 419840K, 100% used [0x00000000e0000000,0x00000000f9a00000,0x00000000f9a00000)
  from space 52224K, 0% used [0x00000000fcd00000,0x00000000fcd00000,0x0000000100000000)
  to   space 52224K, 0% used [0x00000000f9a00000,0x00000000f9a00000,0x00000000fcd00000)
 ParOldGen       total 524288K, used 0K [0x00000000c0000000, 0x00000000e0000000, 0x00000000e0000000)
  object space 524288K, 0% used [0x00000000c0000000,0x00000000c0000000,0x00000000e0000000)
 Metaspace       used 20878K, capacity 21480K, committed 21632K, reserved 1069056K
  class space    used 2766K, capacity 2937K, committed 2944K, reserved 1048576K
2021-03-31T15:23:07.849+0800: 8.961: [GC (Allocation Failure) [PSYoungGen: 419840K->14996K(472064K)] 419840K->15084K(996352K), 0.0182397 secs] [Times: user=0.00 sys=0.01, real=0.02 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 472064K, used 14996K [0x00000000e0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 419840K, 0% used [0x00000000e0000000,0x00000000e0000000,0x00000000f9a00000)
  from space 52224K, 28% used [0x00000000f9a00000,0x00000000fa8a5260,0x00000000fcd00000)
  to   space 52224K, 0% used [0x00000000fcd00000,0x00000000fcd00000,0x0000000100000000)
 ParOldGen       total 524288K, used 88K [0x00000000c0000000, 0x00000000e0000000, 0x00000000e0000000)
  object space 524288K, 0% used [0x00000000c0000000,0x00000000c0016010,0x00000000e0000000)
 Metaspace       used 20878K, capacity 21480K, committed 21632K, reserved 1069056K
  class space    used 2766K, capacity 2937K, committed 2944K, reserved 1048576K
}
-XX:+PrintFlagsFinal

You can add the -XX:+PrintFlagsFinal parameter to the startup parameters, and all the parameters of the system will be printed, and you can see the parameters you configured or the default parameters of the system. This parameter configuration is temporarily not used, only when checking the system configuration It will only be used when it is time, or you can view the configuration parameters through the Java Visual that comes with JMX or jdk. This is displayed in the system startup parameters:

    uintx MaxMetaspaceExpansion                     = 5451776                             {product}
    uintx MaxMetaspaceFreeRatio                     = 70                                  {product}
    uintx MaxMetaspaceSize                         := 134217728                           {product}
    uintx MaxNewSize                               := 536870912                           {product}
     intx MaxNodeLimit                              = 75000                               {C2 product}
 uint64_t MaxRAM                                    = 0                                   {pd product}
    uintx MaxRAMFraction                            = 4                                   {product}
   double MaxRAMPercentage                          = 25.000000                           {product}
     intx MaxRecursiveInlineLevel                   = 1                                   {product}
    uintx MaxTenuringThreshold                      = 15                                  {product}
     intx MaxTrivialSize                            = 6                                   {product}
     intx MaxVectorSize                             = 32                                  {C2 product}
    uintx MetaspaceSize                            := 134217728                           {pd product}

Summary (GC log printing parameter configuration):

Print GC log parameter configuration:

method one:

Only print detailed GC log and output to the specified file

-XX:+PrintGC
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-Xloggc:./gc.log

result:

2021-03-31T15:31:05.603+0800: 6.487: [GC (Allocation Failure) [PSYoungGen: 419840K->16437K(472064K)] 419840K->16525K(996352K), 0.0220363 secs] [Times: user=0.02 sys=0.02, real=0.02 secs] 
2021-03-31T15:31:11.544+0800: 12.428: [GC (Allocation Failure) [PSYoungGen: 436277K->31456K(472064K)] 436365K->31560K(996352K), 0.0307199 secs] [Times: user=0.06 sys=0.03, real=0.03 secs] 
2021-03-31T15:31:19.701+0800: 20.585: [GC (Allocation Failure) [PSYoungGen: 451296K->38124K(472064K)] 451400K->38252K(996352K), 0.0416391 secs] [Times: user=0.09 sys=0.00, real=0.04 secs] 
2021-03-31T15:31:27.432+0800: 28.315: [GC (Allocation Failure) [PSYoungGen: 457964K->48005K(472064K)] 458092K->48149K(996352K), 0.0587718 secs] [Times: user=0.24 sys=0.00, real=0.06 secs] 

Way two:

Print detailed GC log and output to the specified file, and print the stack information before and after each GC

-XX:+PrintGC
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-XX:+PrintHeapAtGC
-Xloggc:./gc.log

result:

{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 472064K, used 419840K [0x00000000e0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 419840K, 100% used [0x00000000e0000000,0x00000000f9a00000,0x00000000f9a00000)
  from space 52224K, 0% used [0x00000000fcd00000,0x00000000fcd00000,0x0000000100000000)
  to   space 52224K, 0% used [0x00000000f9a00000,0x00000000f9a00000,0x00000000fcd00000)
 ParOldGen       total 524288K, used 0K [0x00000000c0000000, 0x00000000e0000000, 0x00000000e0000000)
  object space 524288K, 0% used [0x00000000c0000000,0x00000000c0000018,0x00000000e0000000)
 Metaspace       used 22318K, capacity 22910K, committed 23168K, reserved 1069056K
  class space    used 2920K, capacity 3095K, committed 3200K, reserved 1048576K
2021-03-31T15:25:31.118+0800: 8.730: [GC (GCLocker Initiated GC) [PSYoungGen: 419840K->16575K(472064K)] 419840K->16663K(996352K), 0.0258389 secs] [Times: user=0.05 sys=0.00, real=0.03 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 472064K, used 16575K [0x00000000e0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 419840K, 0% used [0x00000000e0000000,0x00000000e0000000,0x00000000f9a00000)
  from space 52224K, 31% used [0x00000000f9a00000,0x00000000faa2fcb8,0x00000000fcd00000)
  to   space 52224K, 0% used [0x00000000fcd00000,0x00000000fcd00000,0x0000000100000000)
 ParOldGen       total 524288K, used 88K [0x00000000c0000000, 0x00000000e0000000, 0x00000000e0000000)
  object space 524288K, 0% used [0x00000000c0000000,0x00000000c0016028,0x00000000e0000000)
 Metaspace       used 22318K, capacity 22910K, committed 23168K, reserved 1069056K
  class space    used 2920K, capacity 3095K, committed 3200K, reserved 1048576K
}

JVM parameter online check URL

JVM parameter online check

Guess you like

Origin blog.csdn.net/qq_40093255/article/details/115353528