Tomcat 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:

  • ps -ef | grep java
  • top -b -d 300 -p javapid >> nodetop.log
  • Find the pid for tomcat java process
  • 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

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

Baldeep Hira

bay area programmer working on mobile/tablet/web apps and enterprise cloud apps; ui/ux, html5 and everything else for a prettier web and world

  • San Francisco Bay Area
comments powered by Disqus