Enable Verbose Garbage Collection

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Welcome to this hands-on lab, where we will set Tomcat up to use verbose garbage collection. As part of this lab you will also enable parallel garbage collection.

It is useful to have verbose garbage collection set, to help you troubleshoot your Tomcat instance and its applications.

We are using Apache’s Tomcat, a Java-based application platform built around deploying and managing Java Web Applications. The server provided in this lab environment is running Red Hat Enterprise 8 and has Tomcat 9 pre-installed for you. The Tomcat instance is available on port **8080**.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Test to Ensure You Can Access the Preconfigured Tomcat Instances on Port 8080

Use the Tomcat server’s public IP address and port 8080. Connect to the Tomcat GUI and log in. The username and password to use are the same as what’s provided for CLI access.

To access the server, copy the external IP address and test in your browser by using this IP address and appending the :8080 to it.

For example, if an IP address shown was 3.92.152.3, then you would put the following into your web browser:

http://3.92.152.3:8080

You should see the GUI.

Note: It may take from 3 to 10 mins after the Hands-On Lab has started before you can access the Tomcat servers on Port 8080.

Configure Tomcat to Use Verbose and Parallel Garbage Collection

You will need to set options for Tomcat’s startup routine so that it uses verbose and parallel garbage collection.

The options to add to the Tomcat startup file (you may need to create the file) are the following:

  • Verbose garbage collection:
    -verbose:gc
  • Parallel Garbage collection:
    -XX:-UseParallelGC

These entries should be exported as CATALINA_OPTS.

Restart Tomcat and Monitor the Logs for GC Messages

Restart the Tomcat server.

Check the Tomcat logs for entries relating to garbage collection. The log to look into is the catalina.out log.

An example verbose log entry might look like the following:

[2.536s][info][gc] GC(0) Pause Young (Allocation Failure) 66M->7M(1015M) 22.821ms

Additional Resources

Someone discovered that your Tomcat server has been having some performance problems. It has been decided that you should enable verbose garbage collection. It's also been suggested that you enable parallel garbage collection for the server.

You will need to create a bin/setenv.sh script, then add the verbose and parallel garbage collection options.

This is the option for using the verbose garbage collection:

-verbose:gc

This is the option for the parallel garbage collection:

-XX:-UseParallelGC

Once you have added these options to the Tomcat startup routine, you should see entries in the relevant log that relates to garbage collection.

The Tomcat installation directory is /usr/local/tomcat9.

Note: It may take 3 to 10 minutes after the hands-on lab has started before you are able to log into the server. This is fine and will not affect the performance of the tasks for the hands-on lab.

Logging In

Use the credentials provided on the hands-on lab overview page, and log in to the provided server as cloud_user. Note that this is for connecting to the server and also to the Tomcat GUI.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?