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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Languages
  4. Enabling and Analyzing the Garbage Collection Log

Enabling and Analyzing the Garbage Collection Log

An in-depth look at the garbage collection logs produced by JVMs, how to enable this feature and fine tune it. Useful for anyone coding on the JVM (Java, Scala, JRuby, Clojure, etc...)

Siva Prasad Rao Janapati user avatar by
Siva Prasad Rao Janapati
·
Aug. 30, 16 · Tutorial
Like (15)
Save
Tweet
Share
82.53K Views

Join the DZone community and get the full member experience.

Join For Free

In the last article we discussed on the Garbage Collection process. In this article we will learn how to enable the garbage collection log and see what insights we will get from the GC log to tune the JVM.

As a developer, everyone will get a question about enabling the GC log on production servers. Is it advisable to enable GC log on production server? Yes, it is recommended to enable the GC log on production servers. The overhead by enabling the GC log on the JVM is minimal. As per Standard Performance Evaluation Corporation (SPEC), the world record high performance Java Enterprise production servers are running with GC log enabled. First, have to pass the JVM arguments to enable the GC log. Below are the options given for JDK8 Oracle HotSpot JVM.

Note: Set the heap size as low to get the GC log for this exercise:

-XX:+DisableExplicitGC
-XX:+PrintGCDetails
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintGCDateStamps
-Xloggc:gclog.log
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=2000k

Let us understand the purpose of each option. These options may vary based on the OS, JVM vendor, and Java version.

DisableExplicitGC: By default this option is disabled. Sometimes developers might have invoked garbage collection pragmatically by calling System.gc() or Runtime.getRuntime().gc(). This is not advisable. Hence in production systems we enable this option so that the pragmatic invocation of garbage collection is disabled.

PrintGCDetails: By default this option is disabled. If we enable this option, the JVM prints more details at each garbage collection.

PrintGCApplicationStoppedTime: By default this option is disabled. If we enable it, it prints the information on application pause during GC.

PrintGCApplicationConcurrentTime: By default this option is disabled. If we enable it, it prints the information on application running time during GC.

PrintGCDateStamps: By default this option is disabled. If we enable it, it prints the date and time details at each GC.

loggc: This is a string option. We have have to pass the gc log file name. In this file we will get all the GC log information.

UseGCLogFileRotation: This option makes the JVM rotate the log file if the file size reaches a specified size.

NumberOfGCLogFiles: The default value is 1. This sets the number of files to use when rotating logs.

GCLogFileSize: The default value is 8KB, which is the size of the log file before the point the where the log will be rotated.

By setting the above options, we are ready to get the GC log. To tune the JVM, it is better to enable these options during the load test and take the GC log on different loads for analysis. From the GC log we have to observe the below parameters.

  1. How often are the Young GC and Full GC occurring? There should be a several-minute time gap between the GC events. If the Young GC is happening more often, then we might need to look at the allocated Young Gen space. If the Full GC is happening more often, then we need to look at the allocated heap size. 
  2. How much time each GC event is taking to complete? Ideally the Young GC will take a couple of milliseconds, and the Full GC will take a couple of milliseconds to seconds. In any circumstance, if the GC is taking several seconds to minutes, then we have to look at the Heap size tuning. If the GC thread takes more time to complete than garbage collection, the application threads will be in a wait state (GC is a stop the world event). This impacts the user experience.

I have created a sample application to generate a GC log. Now, we will understand the issues here.

gclog analysis

There are some GC log viewers. Here is the one of the GC log analyzers (http://gceasy.io/). If you upload the GC log, it will provide detailed analysis with the charts to understand it. Based on the GC analysis, we can tune the heap size, young gen space, and tenured space. In future articles, we will discuss the different performance-related JVM options. Stay Tuned!

garbage collection Garbage (computer science)

Published at DZone with permission of Siva Prasad Rao Janapati, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Build an Effective CI/CD Pipeline
  • Apache Kafka Is NOT Real Real-Time Data Streaming!
  • GitLab vs Jenkins: Which Is the Best CI/CD Tool?
  • Spring Cloud

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: