In Java, garbage collection (GC) efficiency has a huge impact on system performance. When running as it should, GC adds very little overhead to the application, quietly doing its job in the background. When it goes wrong, it results in high CPU usage and long pauses, degrading response times and possibly impacting on other running applications.

Additionally, GC logs hold key insights into whether the heap is sized and tuned correctly. It’s therefore essential with critical systems to monitor and analyze these logs, and make tuning adjustments as needed.

Since GC logs can occupy thousands of lines, it’s not usually practical to examine them manually for insights. Instead, we’d use a GC log analyzer.

In this article, we’ll look at a few GC analysis tools that make log monitoring simple.

What is The Purpose of a GC Log Analyzer?

GC analysis tools such as GCeasy help us both to solve existing performance problems, and predict future bottlenecks.

You may like to read this article to understand how garbage collection works.

When GC isn’t working correctly, GC events are run more and more frequently, attempting and failing to clear memory. Since the GC must pause all other threads to carry out critical tasks, the application may become unresponsive. GC is very CPU-intensive, so the application uses more and more CPU. Eventually, GC events may be running back-to-back, and application threads can’t do their job. This may happen for several reasons, including:

  • The heap or metaspace has been configured too small. Obviously, the device or container must also have sufficient RAM to cater for the configured sizes.
  • The JVM is not configured to use the best GC algorithm for the type of task.
  • The young and old generation spaces aren’t configured to best advantage.
  • The application has a memory leak, or is wasting memory.

For practical tips on how to tune the JVM, this video is very helpful: Tuning & Troubleshooting Crash Course.

Key Information That Can Be Extracted From GC Logs

To tune the JVM correctly, good information is essential. A good analysis tool can extract a wealth of data from the logs, including:

  • Key performance indicators such as throughput, latency and footprint;
  • Causes of GC events;
  • Frequency and duration of events;
  • Heap size by generational space, showing allocated size against peak usage;
  • GC patterns.

For a description of GC logs, and how to obtain them, you may like to read A Guide to GC Logs. It’s advisable to always enable GC logging in production, since it adds almost no overhead to the application, and we never know when we’ll need the logs. When tuning or troubleshooting, it’s important to analyze logs from at least a full 24-hour period to ensure peak times are included.

The 5 Best GC Log Analyzers

In this section, we’ll look at five of the most useful and reputable GC analysis tools.

1. GCeasy

GCeasy is available in the cloud, on-premise or via REST APIs that allow it to be included in automatic monitoring or CI/CD pipelines.

When a log is uploaded, GCeasy produces an extensive interactive report, including a number of graphs and charts. The report includes:

  • Troubleshooting and tuning recommendations based on ML analysis of the logs;
  • Key Performance Indicators;
  • Memory allocation and usage by heap space;
  • Analysis of event causes;
  • Graphs of heap space usage against time, indicating GC events.

GCeasy works with log formats produced by a wide range of JVM versions, vendors and GC algorithms.

A sample section of a report is included below.

Fig: Section of GCeasy Report

For a demonstration of this product, see An Easy Way to Analyze GC Logs.

2. GCViewer

GCViewer is an open-source log analyzer available from SourceForge. It’s a desktop GUI application that supports most log formats, although logs from older versions can sometimes produce confusing results.

It can not only upload logs for analysis, but can also watch logs of running JVMs to analyze GC performance in real time.

GCViewer includes summaries, graphs and charts, including information such as:

  • Memory Statistics;
  • Throughput;
  • Number and total duration of pauses;
  • Breakdown of pauses by reason;
  • Graph of heap usage over time.

A sample screenshot is shown below.

Fig: GCViewer Interactive GUI

3. IBM GCMV

IBM Garbage Collector and Memory Visualizer is a good choice when working with IBM’s JVM. It’s available to IBM users as part of the IBM toolset, and it’s also available as an Eclipse plugin.

It doesn’t at this time work well with logs produced by newer JVM versions, but it can be used with non-IBM logs produced by older versions of Java. It has an intuitive GUI interface, and produces several useful graphs, such as memory usage over time split by generational heap space. A screenshot of the tool is shown below.

Fig: IBM GCMV Interactive GUI

It’s also worth mentioning that HP also has a tool available for its users: HP JMeter.

4. VisualGC

VisualGC is available either as a stand-alone tool, or as a plugin for VisualVM, which is an all-purpose monitoring utility. Unlike the other GC analyzers, VisualGC doesn’t upload GC logs, but instead connects to a running JVM, monitoring GC in real time. Since it’s fairly lightweight, it could be installed on a production machine, or it can connect to a remote process if JMX is enabled.

It doesn’t provide as wide a range of information as some of the other tools, but shows essentials, including graphs of memory usage over time, the cause of the last GC event and the time taken.

It’s very useful for taking a quick look at an application, either to get an idea of why performance may be slow, or as part of a system health check. For deeper analysis, it may be necessary to submit logs to a more comprehensive analyzer.

A screenshot of VisualVM’s interactive GUI is shown below.

Fig: VisualVM Interactive Graphs

5. Garbagecat

This is a free, open-source tool available from Garbagecat’s GitHub page.  It’s CLI-based rather than having an interactive GUI, and outputs a detailed report in text format.

It may not be the ideal tool for beginners, but it’s very popular with experienced DevOps due to the wide range of useful information it provides, as well as its troubleshooting and tuning tips.

It supports most logs from OpenJDK derivative JVMs, and it’s an invaluable tuning guide. The text format of the report means we can’t quickly visualize trends, but all the important data is well-summarized.

A section of the text report looks like this:

Fig: Section of Text Report Produced by Garbagecat

Conclusion

GC monitoring and tuning is critical for maintaining good system performance, and a GC log analyzer is an essential part of the DevOps toolbox. In this article, we’ve looked at some of the tools that are easily available. 

GCeasy provides comprehensive, easily-visualized information, as well as tuning suggestions. IBM users may like to use IBM’s tool GCMV, whereas GCViewer is a good, lightweight free tool. VisualGC is great for quickly gaining insights into the GC behavior of running JVMs. Garbagecat, on the other hand, is a popular tool with experienced troubleshooters.

GCeasy is the best all-round GC analysis tool for most situations, but any of these utilities are a first-class aid to decision-making.