Analyzing garbage collection log provides several advantages like: Reduces GC pause time, reduces cloud computing cost, predicts outages, provides effective metrics for capacity planning. To learn about the profound advantages of GC log analysis, please refer to this post. In this post let’s learn how to analyze GC logs?

Basically, there are 3 essential steps when it comes to GC log analysis:

1. Enable GC logs

2. Measurement Duration & Environment

3. Tools to analyze

Let’s discuss these 3 steps now.


1. Enable GC Logs
Even though certain monitoring tools provide Garbage Collection graphs/metrics at real time , they don’t provide a complete set of details to study the GC behavior. GC logs are the best source of information, to study the Garbage Collection behavior. You can enable GC logs, by specifying below JVM arguments in your application:

Java 8 & below versions:

If your application is running on Java 8 & below versions, then pass below arguments:

-XX:+PrintGCDetails -Xloggc:<gc-log-file-path>
Example:
-XX:+PrintGCDetails -Xloggc:/opt/tmp/myapp-gc.log

Java 9 & above versions:

If your application is running on Java 9 & above versions, then pass below arguments:

-Xlog:gc*:file=<gc-log-file-path>
Example:
-Xlog:gc*:file=/opt/tmp/myapp-gc.log

2. Measurement Duration & environment

It’s always best practice to study the GC log for a 24-hour period during a weekday, so that application would have seen both high volume and low volume traffic tide.

It’s best practice to collect the GC logs from the production environment, because garbage collection behavior is heavily influenced by the traffic patterns. It’s hard to simulate production traffic in a test environment. Also overhead added by GC log in production servers is negligible, in fact it’s not even measurable. To learn about overhead added by enabling GC logs, you can refer here

3. Tools to analyze
Once you have captured GC logs, you can use one of the following free tools to analyze the GC logs:

GCeasy
IBM GC & Memory visualizer
HP Jmeter
Garbage Cat

Here is an interesting video clip which walks through the best practices, KPIs, tips & tricks to effectively optimize Garbage collection performance.