DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • All You Need To Know About Garbage Collection in Java
  • Java Memory Management
  • Choosing the Best Garbage Collection Algorithm for Better Performance in Java
  • Heap Memory In Java Applications Performance Testing

Trending

  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  1. DZone
  2. Coding
  3. Languages
  4. What Is a Garbage Collection Log and How Can You Enable and Analyze It?

What Is a Garbage Collection Log and How Can You Enable and Analyze It?

In this article, we cover the basics of garbage collection, and how to analyze logs retrieved from Java-based applications.

By 
Ram Lakshmanan user avatar
Ram Lakshmanan
DZone Core CORE ·
Nov. 07, 17 · Opinion
Likes (4)
Comment
Save
Tweet
Share
53.5K Views

Join the DZone community and get the full member experience.

Join For Free

Objects are created in the memory to service incoming requests. Once requests are serviced, newly created objects will become useless (i.e. garbage). This garbage must be evicted from the memory so that there is enough room created in the memory to service the new incoming requests. If there isn’t sufficient memory, the application can experience poor response times, OutOfMemoryError, and fatal crashes.

In Java, Android, C# etc., garbage collection is automatic, whereas in the several predecessor programming languages (C, C++) the programmer must write code explicitly to release the objects after they are used. So, it’s a major convenience for Java, Android, and C# application developers. But this automatic garbage collection is not free, it comes with a price. Automatic Garbage Collection can have a profound impact on:

  1. Application Response Time
  2. CPU
  3. Memory

Application Response Time

To garbage collect objects automatically, the entire application has to be paused intermittently to mark the objects that are in use and sweep away the objects that are not used. During this pause period, all customer transactions which are in motion in the application will be stalled (i.e. frozen). Depending on the type of GC algorithm and memory settings that you configure, pause times can run from a few milliseconds to a few seconds to a few minutes. Thus, Garbage Collection can affect your application SLA (Service Level Agreement) significantly.

CPU

Garbage collection consumes a lot of CPU cycles. Each application will have thousands/millions of objects sitting in memory. Each object in memory should be investigated periodically to see whether they are in use. If it’s in use, who is referencing it? Are those references still active? If they are not in use, they should be evicted from memory. All these investigations and computation requires a considerable amount of CPU power.

Memory

Of course, poor GC configuration can lead to high memory consumption and vice versa. Most applications saturate memory first before saturating other resources (CPU, network bandwidth, storage). Most applications upgrade their EC2 instance size to get additional memory rather than getting additional CPUs or network bandwidth.

Thus, to have top-notch SLAs and reduce the bill from your cloud hosting provider, your application's garbage collection has to function effectively. In order to study and optimize garbage collection's impact on an application’s performance, one has to enable Garbage Collection Logging. Besides that, garbage collection logs can be used to troubleshoot memory-related problems in the application.

Enabling GC Logs

GC Logging can be enabled by passing in the below-mentioned system properties during application startup.

Until Java 8:

Below is the system property that is supported by all versions of Java until JDK 8.

-XX:+PrintGCDetails -Xloggc:<gc-log-file-path>

Example:

-XX:+PrintGCDetails -Xloggc:/opt/tmp/myapp-gc.log

From Java 9:

Below is the system property that is supported by all versions of Java starting with JDK 9.

-Xlog:gc*:file=<gc-log-file-path>

Example:

-Xlog:gc*:file=/opt/tmp/myapp-gc.log

How to Analyze GC Logs

Here is a sample GC log generated when the above system properties were passed:

What is GC

A GC log has rich information, however, understanding GC logs is not easy. There isn’t sufficient documentation to explain GC log format. On top of that, GC log format is not standardized. It varies by JVM vendor (Oracle, IBM, HP, Azul, …), Java version (1.4, 5, 6, 7, 8, 9), GC algorithm (Serial, Parallel, CMS, G1, Shenandoah), GC system properties that you pass (-XX:+PrintGC, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintHeapAtGC …). Based on this permutation and combination, there are easily 60+ different GC log formats.

Thus, to analyze GC logs, it’s highly recommended to use GC log analysis tools such as GCeasy, HPJmeter. These tools parse GC logs and generate great graphical visualizations of data, reports Key Performance Indicators and several other useful metrics.

Here is a sample GC log analysis report generated by the GCeasy tool.

garbage collection Garbage (computer science) application Analyze (imaging software) Memory (storage engine) Java (programming language) Object (computer science) Log analysis Property (programming)

Opinions expressed by DZone contributors are their own.

Related

  • All You Need To Know About Garbage Collection in Java
  • Java Memory Management
  • Choosing the Best Garbage Collection Algorithm for Better Performance in Java
  • Heap Memory In Java Applications Performance Testing

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!