JVM Debugging

A quick summary of tips & tricks when debugging a webapp running in Tomcat. These come in handy if you’re running into memory issues and want to track down memory leaks.

Run JSTAT with gc option every 300s:

cd saas_prod/java/bin
jps
jstat -gc Bootstrappid 300s >> nodejstat.log
jps and jstat executables are in java bin dir
jps command displays pid named "Bootstrap"
jstat command will sample java memory every 300s

Run TOP in batch mode with 300s delay period:

#find pid of java process
ps -ef | grep java

# The -b option runs top in batch mode
# The -d option sets the sample delay time to every 300s
# The -p option uses the specified pid
top -b -d 300 -p javapid >> nodetop.log

Opening Tomcat Debug Port at 9191:

# Edit catalina.sh file under tomcat/bin
# Edit JAVAOPT variable to add these options
-Xdebug
-Xrunjdwp:transport=dtsocket,address=9191,server=y,suspend=n

Enable verbose GC option for Tomcat:

# Edit catalina.sh file under tomcat/bin
# Edit JAVA_OPT variable to add this option
-verbose:gc

Using JCONSOLE with Tomcat JMX:

# Edit catalina.sh file under tomcat/bin
# Edit JAVA_OPT variable to add these options
  -Dcom.sun.management.jmxremote
  -Dcom.sun.management.jmxremote.port=9292
  -Dcom.sun.management.jmxremote.ssl=false
  -Dcom.sun.management.jmxremote.authenticate=false
# Run jconsole remotely:
java/bin/jconsole hostname:9292