Tag Archives: application server

Enabling GC logs in Apache Tomcat

There are so many way to analyze the performance of Application Server. 1 of those are called GC logs. GC logs is a log to monitor the movement of your application server’s memory usage. GC log is superb to analyze any kind of memory leaks or even analyze your optimization of your application. GC is actually stand for Garbage Collection, method in JVM to collecting all un-used or un-referenced object in memory to free up memory. So, lets get it on!

1. Enabling CATALINA_OPTS option and setting up the GC log enable parameter

You need to enable your CATALINA_OPTS parameter. CATALINA_OPTS is a parameter that allow you to specify a specific option during the startup of your tomcat server, such as the initial parameter for heap space, perm space, and so on. This can be done in 2 ways. In Windows Environment, you can create a new variable in your Environment Variable. Another simpler way, you can go to bin folder of your tomcat directory, find for startup.bat script. Open the script and you can set the CATALINA_OPTS variable. I prefer the second way to be explained since the first one only applicable for Windows user only.
So, open your startup.bat script, and add this code below :

set "CATALINA_OPTS=-Xloggc:log.gc"

at wherever you want (as long as it is put before :end and it is not in between if listing code 😀 ).
The -Xloggc is parameter for enabling GC logs. and log.gc is the name of file that will contain the log for memory. if you write like this, the GC will be created in bin folder right after server getting started up.

2. Start your apache tomcat

Next step, run your startup.bat. Right after the server getting started up, you will see in your bin folder, there will be a file called log.gc as per screen shot below :

If you can see this file, it means you have succesfully enabling your gc log for your performance monitor.

3. Analyze your GC logs

You might want to analyze your GC log since you have enable it and i’m pretty sure that you dont want to open the file using the editor since the content is such a horrible.
There are a lot of tools to analyze it, 1 sample that i take is HPjmeter, 1 of free application too analyze. You can google it to download 1 copy for you. Once you have installed it, you can drag your log.gc file into it, and you can see several options that you can use. Below is the sample screen shot from HPjmeter based on my log.gc :

GC Log Chart Example

GC Log Chart Example

GC Time Duration



Posted by on July 22, 2011 in English, Programming


Tags: , , , ,