+ All Categories
Home > Technology > Troubleshooting Live Java Web Applications

Troubleshooting Live Java Web Applications

Date post: 23-Jan-2015
Category:
Upload: spring-io
View: 468 times
Download: 2 times
Share this document with a friend
Description:
Speaker: Ashley Puls Operations teams tend to get nervous when debugging tools are installed on production systems. This is understandable as most people have had at least one debugging tool crash a system. However, are there tools that can be run in a production environment? This talk will cover methods and tools that can be used to uncover and resolve performance problems arising in Java web applications that use the Spring Framework. This talk will touch on a few common problems such as slow SQL, slow web page load times, blocked threads, and exceptions in the code. It will use a variety of diagnostic tools to examine these problems including log files, jmap, jvisualvm, and New Relic. Finally, the talk will evaluate the use of these tools in a production environment, separating them into what can and cannot be realistically used in live production web applications
272
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Troubleshooting Live Java Web Applications By Ashley Puls Sunday, September 8, 13
Transcript
Page 1: Troubleshooting Live Java Web Applications

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Troubleshooting Live Java Web ApplicationsBy Ashley Puls

Sunday, September 8, 13

Page 2: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 3: Troubleshooting Live Java Web Applications

Troubleshooting

Location and eliminate sources of trouble

Determine and settle problems

A systematic approach to solving problems quickly and efficiently

A logical process of elimination to identify the true source of the problem

Sunday, September 8, 13

Page 4: Troubleshooting Live Java Web Applications

How To Become A Good Troubleshooter

Practice makes perfect

Images From: http://www.tennismindgame.com/image-files/topspin-tennis-serve.jpg

Sunday, September 8, 13

Page 5: Troubleshooting Live Java Web Applications

How To Become A Good Troubleshooter

Practice makes perfect

Images From: http://www.tennismindgame.com/image-files/topspin-tennis-serve.jpg, http://blogs.telerik.com/images/default-source/jeff-fritz/toolbox.jpg?sfvrsn=0

Have a good set of tools

Sunday, September 8, 13

Page 6: Troubleshooting Live Java Web Applications

Outline

examine a web application with multiple performance problems

troubleshoot the problems using several tools

talk about the pros and cons of each tool

Sunday, September 8, 13

Page 7: Troubleshooting Live Java Web Applications

STEP 1: WE NEED AN APPLICATION

Sunday, September 8, 13

Page 8: Troubleshooting Live Java Web Applications

The Application

Dear Developer,

I had some engineers develop “Running Central” to search for runners, races, and training teams. Can you please keep the site running?

Sincerely,Max SiegelCEO of USA Track and Field

Image From: http://www.sportsbusinessdaily.com/Journal/Issues/2012/06/18/Leagues-and-Governing-Bodies/~/media/8C99287D3B0E4784932EE3BF049E7DA9.ashx

Sunday, September 8, 13

Page 9: Troubleshooting Live Java Web Applications

The Application

MySQL Database

hibernate

racerunners.war

jsp

Client

Client

Client

Servlet

Controller

Manager

Entities

Tomcat Application Server

Sunday, September 8, 13

Page 10: Troubleshooting Live Java Web Applications

WE HAVE OUR APPLICATION

SHOULD WE JUST JUMP INTO TROUBLESHOOTING?

Image From: http://toosoxy.files.wordpress.com/2011/04/cliff.jpg

Sunday, September 8, 13

Page 11: Troubleshooting Live Java Web Applications

What Is Trouble?

Image From: http://1.bp.blogspot.com/-_LgC3yz9w4w/T4eI--IcvxI/AAAAAAAAA-o/VLdqkxyQpgg/s400/computerFire.jpg

Sunday, September 8, 13

Page 12: Troubleshooting Live Java Web Applications

Site InaccessibleWhat Is Trouble?

Sunday, September 8, 13

Page 13: Troubleshooting Live Java Web Applications

Site Inaccessible

ExceptionsIn Logs

What Is Trouble?

Sunday, September 8, 13

Page 14: Troubleshooting Live Java Web Applications

Site Inaccessible

ExceptionsIn Logs

Loading Slowly

What Is Trouble?

Sunday, September 8, 13

Page 15: Troubleshooting Live Java Web Applications

What Is Normal?

Images From: http://espn.go.com/mlb/statistics, http://www.franklinbaseball.com/pros/american-league/central/miguel-cabrera

Sunday, September 8, 13

Page 16: Troubleshooting Live Java Web Applications

Errorserrors within application

Application Response Time

time per request

Database Response Time

time per request

Thread Stateactive thread states

Garbage Collectiontime spent in GC

Memory Allocationheap and PermGen

What Are The Stats?

Sunday, September 8, 13

Page 17: Troubleshooting Live Java Web Applications

How To Gather The Stats

Logs

core JDK tools

Application Performance Monitoring Tools (APM)

Profiler

JMX Metrics

Framework/App Server Monitoring Tools

Sunday, September 8, 13

Page 18: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Basic Information

Basic information about each tool

Sunday, September 8, 13

Page 19: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

What data does each tool provide?

Sunday, September 8, 13

Page 20: Troubleshooting Live Java Web Applications

LETS TALK TO SOME OF OUR USERS AND START

TROUBLESHOOTING

Sunday, September 8, 13

Page 21: Troubleshooting Live Java Web Applications

Image From: http://resources0.news.com.au/images/2012/08/10/1226447/688548-usain-bolt.jpg

Sunday, September 8, 13

Page 22: Troubleshooting Live Java Web Applications

Image From: http://resources0.news.com.au/images/2012/08/10/1226447/688548-usain-bolt.jpg

Usain Bolt : Six Time Olympic Champion

Sunday, September 8, 13

Page 23: Troubleshooting Live Java Web Applications

I was looking for a 5K race on your site,

but it was loading like I was on a 56k

Image From: http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2012/8/9/1344533810934/f582144a-9dd2-44ed-9828-0ec1f5f768a8-460.jpeg

Sunday, September 8, 13

Page 24: Troubleshooting Live Java Web Applications

LETS INVESTIGATE!

Sunday, September 8, 13

Page 25: Troubleshooting Live Java Web Applications

New Relic

Application Performance Monitoring (APM) tool that monitors web

apps, mobile apps, servers, and databases

Sign up and download agent from the New Relic Website

Sunday, September 8, 13

Page 26: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Basic Information

Sunday, September 8, 13

Page 27: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 28: Troubleshooting Live Java Web Applications

Application Response Time

Sunday, September 8, 13

Page 29: Troubleshooting Live Java Web Applications

Application Response Time

Error InformationSunday, September 8, 13

Page 30: Troubleshooting Live Java Web Applications

Application Response Time

Error InformationSunday, September 8, 13

Page 31: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 32: Troubleshooting Live Java Web Applications

Heap Memory

Sunday, September 8, 13

Page 33: Troubleshooting Live Java Web Applications

Heap Memory

Non-Heap Memory

Sunday, September 8, 13

Page 34: Troubleshooting Live Java Web Applications

Garbage Collection

Sunday, September 8, 13

Page 35: Troubleshooting Live Java Web Applications

Heap Memory Non- Heap Memory

Other

Class Instances

Arrays

Runtime constant pool

Interned Strings

Field and method data

JVM internal

structures

JVM Memory

Sunday, September 8, 13

Page 36: Troubleshooting Live Java Web Applications

Heap Memory Non- Heap Memory

Other

Common Memory Problems

Keeping references to old objects

Long term objects never cleaned up

Leaky class loaders

Interning an excessive number

of Strings

Sunday, September 8, 13

Page 37: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 38: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 39: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 40: Troubleshooting Live Java Web Applications

JMap

Prints the memory map of a Java process

Commands

jmap -heap JAVA_PID > /tmp/jmap.out

jmap -dump:file=/tmp/heap_dump.map JAVA_PID

Sunday, September 8, 13

Page 41: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit

JVisualVm

JConsole

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack

Basic Information

Sunday, September 8, 13

Page 42: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 43: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 44: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 45: Troubleshooting Live Java Web Applications

The File

Heap Memory

Sunday, September 8, 13

Page 46: Troubleshooting Live Java Web Applications

The File

Heap Memory

Non-Heap Memory

Sunday, September 8, 13

Page 47: Troubleshooting Live Java Web Applications

The File

Heap Memory

Non-Heap Memory

Sunday, September 8, 13

Page 48: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 49: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 50: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 51: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 52: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 53: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 54: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 55: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 56: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 57: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 58: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 59: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 60: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 61: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 62: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 63: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 64: Troubleshooting Live Java Web Applications

YourKit

Profiler that provides in depth CPU, thread, and memory profiling

Get license key and download from YourKit Website

Sunday, September 8, 13

Page 65: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm

JConsole

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack

Basic Information

Sunday, September 8, 13

Page 66: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 67: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 68: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 69: Troubleshooting Live Java Web Applications

Thread Count

Sunday, September 8, 13

Page 70: Troubleshooting Live Java Web Applications

Thread Count

Error Rate

Sunday, September 8, 13

Page 71: Troubleshooting Live Java Web Applications

Thread Count

Error Rate

Sunday, September 8, 13

Page 72: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 73: Troubleshooting Live Java Web Applications

Thread Information

Sunday, September 8, 13

Page 74: Troubleshooting Live Java Web Applications

Thread Information

Sunday, September 8, 13

Page 75: Troubleshooting Live Java Web Applications

Non-Heap Memory

Heap Memory

Sunday, September 8, 13

Page 76: Troubleshooting Live Java Web Applications

Non-Heap Memory

Heap Memory

Sunday, September 8, 13

Page 77: Troubleshooting Live Java Web Applications

GC Information

Sunday, September 8, 13

Page 78: Troubleshooting Live Java Web Applications

Run a CPU profile

Sunday, September 8, 13

Page 79: Troubleshooting Live Java Web Applications

Application Response Times

Sunday, September 8, 13

Page 80: Troubleshooting Live Java Web Applications

Application Response Times

Sunday, September 8, 13

Page 81: Troubleshooting Live Java Web Applications

Database Response Times

Sunday, September 8, 13

Page 82: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 83: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 84: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 85: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 86: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 87: Troubleshooting Live Java Web Applications

/** * This service records stats on the cities and states queried by users when looking for races. The stats are * printed out to the log. */public class RaceStatsServiceImpl implements RaceStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final Integer ONE = Integer.valueOf(1); private static final long DELAY = 1; /** Executer service which executes the thread that compiles stats and prints them to the log. */ private final ScheduledExecutorService scheduledExecutor; /** Holds the cities queried by users in the last minute. */ private final Map<String, Integer> citiesQueried; /** Holds the states queried in the last minute. */ private final Map<String, Integer> stateQueried;

public RaceStatsServiceImpl() { citiesQueried = new ConcurrentHashMap<String, Integer>(); stateQueried = new ConcurrentHashMap<String, Integer>(); // Calls the processor thread’s run method every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new Processor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * This should be called every time a city or state is used to search for races. * * @param city The city that was queried. * @param state The state that was queried. */ public void addLocation(String city, String state) { if (city != null && !city.isEmpty()) { addToMap(citiesQueried, city.trim()); } if (state != null && state.isEmpty()) { addToMap(stateQueried, state); } }

Sunday, September 8, 13

Page 88: Troubleshooting Live Java Web Applications

/** * This service records stats on the cities and states queried by users when looking for races. The stats are * printed out to the log. */public class RaceStatsServiceImpl implements RaceStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final Integer ONE = Integer.valueOf(1); private static final long DELAY = 1; /** Executer service which executes the thread that compiles stats and prints them to the log. */ private final ScheduledExecutorService scheduledExecutor; /** Holds the cities queried by users in the last minute. */ private final Map<String, Integer> citiesQueried; /** Holds the states queried in the last minute. */ private final Map<String, Integer> stateQueried;

public RaceStatsServiceImpl() { citiesQueried = new ConcurrentHashMap<String, Integer>(); stateQueried = new ConcurrentHashMap<String, Integer>(); // Calls the processor thread’s run method every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new Processor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * This should be called every time a city or state is used to search for races. * * @param city The city that was queried. * @param state The state that was queried. */ public void addLocation(String city, String state) { if (city != null && !city.isEmpty()) { addToMap(citiesQueried, city.trim()); } if (state != null && state.isEmpty()) { addToMap(stateQueried, state); } }

Two ConcurrentHashMaps

Sunday, September 8, 13

Page 89: Troubleshooting Live Java Web Applications

/** * This service records stats on the cities and states queried by users when looking for races. The stats are * printed out to the log. */public class RaceStatsServiceImpl implements RaceStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final Integer ONE = Integer.valueOf(1); private static final long DELAY = 1; /** Executer service which executes the thread that compiles stats and prints them to the log. */ private final ScheduledExecutorService scheduledExecutor; /** Holds the cities queried by users in the last minute. */ private final Map<String, Integer> citiesQueried; /** Holds the states queried in the last minute. */ private final Map<String, Integer> stateQueried;

public RaceStatsServiceImpl() { citiesQueried = new ConcurrentHashMap<String, Integer>(); stateQueried = new ConcurrentHashMap<String, Integer>(); // Calls the processor thread’s run method every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new Processor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * This should be called every time a city or state is used to search for races. * * @param city The city that was queried. * @param state The state that was queried. */ public void addLocation(String city, String state) { if (city != null && !city.isEmpty()) { addToMap(citiesQueried, city.trim()); } if (state != null && state.isEmpty()) { addToMap(stateQueried, state); } }

Two ConcurrentHashMaps

Sunday, September 8, 13

Page 90: Troubleshooting Live Java Web Applications

/** * Thread that runs periodically and reports the frequency that cities and states are queried to the log. */ private final class Processor extends Thread {

/** * Creates this Processor. */ public Processor() { super(); }

/** * Prints each city and state that was queried by a user since the Processor thread was last run. */ @Override public void run() { StringBuilder sb = new StringBuilder("(Race City Query:Count: "); Iterator<Entry<String, Integer>> cityIt = citiesQueried.entrySet().iterator(); Entry<String, Integer> current; while (cityIt.hasNext()) { current = cityIt.next(); sb.append(current.getKey()).append(":").append(current.getValue()).append(" "); }

sb.append("\nRace State Query:Count: "); Iterator<Entry<String, Integer>> stateIt = stateQueried.entrySet().iterator(); while (stateIt.hasNext()) { current = stateIt.next(); sb.append(current.getKey()).append(current.getValue()).append(" "); } LOGGER.log(Level.INFO, sb.toString()); } }

Sunday, September 8, 13

Page 91: Troubleshooting Live Java Web Applications

/** * Thread that runs periodically and reports the frequency that cities and states are queried to the log. */ private final class Processor extends Thread {

/** * Creates this Processor. */ public Processor() { super(); }

/** * Prints each city and state that was queried by a user since the Processor thread was last run. */ @Override public void run() { StringBuilder sb = new StringBuilder("(Race City Query:Count: "); Iterator<Entry<String, Integer>> cityIt = citiesQueried.entrySet().iterator(); Entry<String, Integer> current; while (cityIt.hasNext()) { current = cityIt.next(); sb.append(current.getKey()).append(":").append(current.getValue()).append(" "); }

sb.append("\nRace State Query:Count: "); Iterator<Entry<String, Integer>> stateIt = stateQueried.entrySet().iterator(); while (stateIt.hasNext()) { current = stateIt.next(); sb.append(current.getKey()).append(current.getValue()).append(" "); } LOGGER.log(Level.INFO, sb.toString()); } }

Processor is an inner class of RaceStatsServiceImpl

Sunday, September 8, 13

Page 92: Troubleshooting Live Java Web Applications

/** * Thread that runs periodically and reports the frequency that cities and states are queried to the log. */ private final class Processor extends Thread {

/** * Creates this Processor. */ public Processor() { super(); }

/** * Prints each city and state that was queried by a user since the Processor thread was last run. */ @Override public void run() { StringBuilder sb = new StringBuilder("(Race City Query:Count: "); Iterator<Entry<String, Integer>> cityIt = citiesQueried.entrySet().iterator(); Entry<String, Integer> current; while (cityIt.hasNext()) { current = cityIt.next(); sb.append(current.getKey()).append(":").append(current.getValue()).append(" "); }

sb.append("\nRace State Query:Count: "); Iterator<Entry<String, Integer>> stateIt = stateQueried.entrySet().iterator(); while (stateIt.hasNext()) { current = stateIt.next(); sb.append(current.getKey()).append(current.getValue()).append(" "); } LOGGER.log(Level.INFO, sb.toString()); } }

Processor is an inner class of RaceStatsServiceImpl

Two ConcurrentHashMaps

Sunday, September 8, 13

Page 93: Troubleshooting Live Java Web Applications

private final class Processor extends Thread {

/** * Creates this Processor. */ public Processor() { super(); }

/** * Prints each city and state that was queried by a user since the Processor thread was last run. */ @Override public void run() { StringBuilder sb = new StringBuilder("(Race City Query:Count: "); Iterator<Entry<String, Integer>> cityIt = citiesQueried.entrySet().iterator(); Entry<String, Integer> current; while (cityIt.hasNext()) { current = cityIt.next(); sb.append(current.getKey()).append(":").append(current.getValue()).append(" "); cityIt.remove(); }

sb.append("\nRace State Query:Count: "); Iterator<Entry<String, Integer>> stateIt = stateQueried.entrySet().iterator(); while (stateIt.hasNext()) { current = stateIt.next(); sb.append(current.getKey()).append(current.getValue()).append(" "); stateIt.remove(); } LOGGER.log(Level.INFO, sb.toString()); } }

Sunday, September 8, 13

Page 94: Troubleshooting Live Java Web Applications

SOLUTION

CLEAN UP MEMORY IN LONG RUNNING OBJECTS

Sunday, September 8, 13

Page 95: Troubleshooting Live Java Web Applications

AFTER THE FIX

Sunday, September 8, 13

Page 96: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 97: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 98: Troubleshooting Live Java Web Applications

Image From: http://news.images.itv.com/image/file/69820/article_9e6cab04948b5c33_1343574136_9j-4aaqsk.jpeg

Sunday, September 8, 13

Page 99: Troubleshooting Live Java Web Applications

Image From: http://news.images.itv.com/image/file/69820/article_9e6cab04948b5c33_1343574136_9j-4aaqsk.jpeg

Paula RadcliffeFemale Marathon World Record Holder

Sunday, September 8, 13

Page 100: Troubleshooting Live Java Web Applications

Image From: http://i3.manchestereveningnews.co.uk/incoming/article660410.ece/ALTERNATES/s615/C_71_article_1584722_image_list_image_list_item_0_image-660410.jpg

It was taking too long to find my fellow runners on

your site

Sunday, September 8, 13

Page 101: Troubleshooting Live Java Web Applications

LETS INVESTIGATE!

Sunday, September 8, 13

Page 102: Troubleshooting Live Java Web Applications

JVisualVM

Visual tool which provides heap dumps, memory leak information,

garbage collection monitoring, memory profiling, and CPU profiling

Attaches to local and remote running processes

Sunday, September 8, 13

Page 103: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm profiler no yes yes

JConsole

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack

Basic Information

Sunday, September 8, 13

Page 104: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 105: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 106: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 107: Troubleshooting Live Java Web Applications

GC Information

Sunday, September 8, 13

Page 108: Troubleshooting Live Java Web Applications

Memory Information

GC Information

Sunday, September 8, 13

Page 109: Troubleshooting Live Java Web Applications

Thread Information

Memory Information

GC Information

Sunday, September 8, 13

Page 110: Troubleshooting Live Java Web Applications

Thread Information

GC Information

Memory Information

Sunday, September 8, 13

Page 111: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 112: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 113: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 114: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 115: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 116: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 117: Troubleshooting Live Java Web Applications

Kill Dash 3

Provides the current stack trace for each thread in a local JVM (thread dump)

Available on linux and macs (ctrl+break on windows)

Command: kill -3 PID

Sunday, September 8, 13

Page 118: Troubleshooting Live Java Web Applications

JStack

Provides the current stack trace for each thread in a local or remote

JVM (thread dump)

Command: jstack -l JAVA_PID > /tmp/jstack.out

Sunday, September 8, 13

Page 119: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring

New Relic APM Solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm profiler no yes yes

JConsole

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack prints thread dump of Java process

no, attaches to running process yes yes

Basic Information

Sunday, September 8, 13

Page 120: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 121: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 122: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 123: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 124: Troubleshooting Live Java Web Applications

New Relic

Application Performance Monitoring (APM) tool that monitors web

apps, mobile apps, servers, and databases

Sign up and download agent from the New Relic Website

Sunday, September 8, 13

Page 125: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 126: Troubleshooting Live Java Web Applications

Thread Count

Sunday, September 8, 13

Page 127: Troubleshooting Live Java Web Applications

Thread Count

Sunday, September 8, 13

Page 128: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 129: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 130: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 131: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 132: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 133: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 134: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 135: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 136: Troubleshooting Live Java Web Applications

/** * Stores stats on the last names of runners which have been queried. */public class RunnerStatsServiceImpl implements RunnerStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final long DELAY = 1; /** Executor service which schedules the StatsProcessor thread to run every minute. */ private final ScheduledExecutorService scheduledExecutor; /** Stores the last name of queried runners. */ private final Queue<String> lastNamesQueried;

public RunnerStatsServiceImpl() { lastNamesQueried = new ArrayBlockingQueue<String>(100); // reports the metrics to the log every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new StatsProcessor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * Adds an entry in the stats. * * @param lastName A last name that was queried. */ public void addEntries(String lastName) {

if (lastName != null && !lastName.isEmpty()) { while (!lastNamesQueried.offer(lastName.trim())) { try { Thread.sleep(100); } catch (InterruptedException e) { // ignore this exception } } } }

Sunday, September 8, 13

Page 137: Troubleshooting Live Java Web Applications

/** * Stores stats on the last names of runners which have been queried. */public class RunnerStatsServiceImpl implements RunnerStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final long DELAY = 1; /** Executor service which schedules the StatsProcessor thread to run every minute. */ private final ScheduledExecutorService scheduledExecutor; /** Stores the last name of queried runners. */ private final Queue<String> lastNamesQueried;

public RunnerStatsServiceImpl() { lastNamesQueried = new ArrayBlockingQueue<String>(100); // reports the metrics to the log every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new StatsProcessor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * Adds an entry in the stats. * * @param lastName A last name that was queried. */ public void addEntries(String lastName) {

if (lastName != null && !lastName.isEmpty()) { while (!lastNamesQueried.offer(lastName.trim())) { try { Thread.sleep(100); } catch (InterruptedException e) { // ignore this exception } } } }

Where the threads are sleeping

Sunday, September 8, 13

Page 138: Troubleshooting Live Java Web Applications

/** * Stores stats on the last names of runners which have been queried. */public class RunnerStatsServiceImpl implements RunnerStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final long DELAY = 1; /** Executor service which schedules the StatsProcessor thread to run every minute. */ private final ScheduledExecutorService scheduledExecutor; /** Stores the last name of queried runners. */ private final Queue<String> lastNamesQueried;

public RunnerStatsServiceImpl() { lastNamesQueried = new ArrayBlockingQueue<String>(100); // reports the metrics to the log every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new StatsProcessor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * Adds an entry in the stats. * * @param lastName A last name that was queried. */ public void addEntries(String lastName) {

if (lastName != null && !lastName.isEmpty()) { while (!lastNamesQueried.offer(lastName.trim())) { try { Thread.sleep(100); } catch (InterruptedException e) { // ignore this exception } } } }

Where the threads are sleeping

queue blocking at 100 strings

Sunday, September 8, 13

Page 139: Troubleshooting Live Java Web Applications

/** * Stores stats on the last names of runners which have been queried. */public class RunnerStatsServiceImpl implements RunnerStatsService {

private static final Logger LOGGER = LoggingUtils.getLogger(RunnerStatsServiceImpl.class.getName()); private static final long DELAY = 1; /** Executor service which schedules the StatsProcessor thread to run every minute. */ private final ScheduledExecutorService scheduledExecutor; /** Stores the last name of queried runners. */ private final Queue<String> lastNamesQueried;

public RunnerStatsServiceImpl() { lastNamesQueried = new ArrayBlockingQueue<String>(100); // reports the metrics to the log every minute scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleAtFixedRate(new StatsProcessor(), DELAY, DELAY, TimeUnit.MINUTES); }

/** * Adds an entry in the stats. * * @param lastName A last name that was queried. */ public void addEntries(String lastName) {

if (lastName != null && !lastName.isEmpty()) { while (!lastNamesQueried.offer(lastName.trim())) { try { Thread.sleep(100); } catch (InterruptedException e) { // ignore this exception } } } }

Where the threads are sleeping

queue blocking at 100 strings

Sunday, September 8, 13

Page 140: Troubleshooting Live Java Web Applications

SOLUTION

DO NOT BLOCK THREADS

Sunday, September 8, 13

Page 141: Troubleshooting Live Java Web Applications

AFTER THE FIX

Sunday, September 8, 13

Page 142: Troubleshooting Live Java Web Applications

The File

Sunday, September 8, 13

Page 143: Troubleshooting Live Java Web Applications

The File

waiting for more requests to come in

Sunday, September 8, 13

Page 144: Troubleshooting Live Java Web Applications

Image From: http://www.webrun.com.br/multimidia/fotos/2011/20110926_175711_g.jpg

Sunday, September 8, 13

Page 145: Troubleshooting Live Java Web Applications

Image From: http://www.webrun.com.br/multimidia/fotos/2011/20110926_175711_g.jpg

Patrick Makau Musyoki

Marathon World Record Holder

Sunday, September 8, 13

Page 146: Troubleshooting Live Java Web Applications

Image From: http://simonfreeman.co.uk/wp-content/uploads/2013/04/image-4.jpeg

I tried to look for marathons on your site but could not access it

Sunday, September 8, 13

Page 147: Troubleshooting Live Java Web Applications

LETS INVESTIGATE!

Sunday, September 8, 13

Page 148: Troubleshooting Live Java Web Applications

New Relic

Application Performance Monitoring (APM) tool that monitors web

apps, mobile apps, servers, and databases

Sign up and download agent from the New Relic Website

Sunday, September 8, 13

Page 149: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 150: Troubleshooting Live Java Web Applications

JConsole

Graphical User Interface (GUI) which displays Java Management

Extension (JMX) metrics for a local or remote JVMs

JMX metrics should be enabled in your application server

Sunday, September 8, 13

Page 151: Troubleshooting Live Java Web Applications

Tools Overview Installation Cost Include With JDK

Logs

App Server Monitoring

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm profiler no yes yes

JConsole JMX metrics no yes yes

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack prints thread dump of Java process

no, attaches to running process yes yes

Basic Information

Sunday, September 8, 13

Page 152: Troubleshooting Live Java Web Applications

Tools Overview Installation Cost Include With JDK

Logs

App Server Monitoring

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm profiler no yes yes

JConsole JMX metrics no yes yes

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack prints thread dump of Java process

no, attaches to running process yes yes

Basic Information

Sunday, September 8, 13

Page 153: Troubleshooting Live Java Web Applications

JMX

MBean MBean MBean

Managed beans (mbeans) represent resources. They are a remotely accessible interface into a resource that provides stats and can be used to manipulate the resource.

Examples include applications, JDBC drivers, garbage collection mechanisms, and thread pools.

Sunday, September 8, 13

Page 154: Troubleshooting Live Java Web Applications

JMX

MBean MBean MBean

MBean Server

The mbean server acts as the intermediary between the mbeans and the application requesting the information.

Mbeans can be created, registered, and deleted through the server.

Sunday, September 8, 13

Page 155: Troubleshooting Live Java Web Applications

JMX

MBean MBean MBean

MBean Server

Connector Adaptor

JConsole

Sunday, September 8, 13

Page 156: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 157: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 158: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 159: Troubleshooting Live Java Web Applications

Memory Information

Sunday, September 8, 13

Page 160: Troubleshooting Live Java Web Applications

Memory InformationThread Information

Sunday, September 8, 13

Page 161: Troubleshooting Live Java Web Applications

Memory InformationThread Information

Sunday, September 8, 13

Page 162: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 163: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 164: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 165: Troubleshooting Live Java Web Applications

JVM specific mbeans

Sunday, September 8, 13

Page 166: Troubleshooting Live Java Web Applications

Tomcat Application Server mbeans

JVM specific mbeans

Sunday, September 8, 13

Page 167: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 168: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 169: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 170: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 171: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 172: Troubleshooting Live Java Web Applications

CAN YOU DO THIS IN JVISUALVM?

Sunday, September 8, 13

Page 173: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 174: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 175: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 176: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 177: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 178: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 179: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 180: Troubleshooting Live Java Web Applications

Tomcat Application Server mbeans

JVM specific mbeans

Sunday, September 8, 13

Page 181: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 182: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 183: Troubleshooting Live Java Web Applications

The File vi tomcat/config/server.xml

Sunday, September 8, 13

Page 184: Troubleshooting Live Java Web Applications

The File vi tomcat/config/server.xml

Sunday, September 8, 13

Page 185: Troubleshooting Live Java Web Applications

The File vi tomcat/config/server.xml

Sunday, September 8, 13

Page 186: Troubleshooting Live Java Web Applications

THREAD POOLS NEEDED TO BE TUNED

SOLUTION

Sunday, September 8, 13

Page 187: Troubleshooting Live Java Web Applications

What Should Be The Size Of The Pool?

• If the pool size is too small, then requests back up

Image From: http://terrortrendsbulletin.files.wordpress.com/2012/11/airport-security-lines1.jpg

Sunday, September 8, 13

Page 188: Troubleshooting Live Java Web Applications

What Should Be The Size Of The Pool?

• If the pool size is too large, then system resources

might become exhausted

Sunday, September 8, 13

Page 189: Troubleshooting Live Java Web Applications

What Should Be The Size Of The Pool?

• If the pool size is too large, then system resources

might become exhausted

Image From: http://static.ddmcdn.com/gif/airport-security-detector1.jpg

Sunday, September 8, 13

Page 190: Troubleshooting Live Java Web Applications

What Should Be The Size Of The Pool?

• If the pool size is too large, then system resources

might become exhausted

Images From: http://static.ddmcdn.com/gif/airport-security-detector1.jpg, http://graphics8.nytimes.com/images/2012/10/07/travel/07GETAWAY_SPAN/07GETAWAY_SPAN-articleLarge.jpg

Sunday, September 8, 13

Page 191: Troubleshooting Live Java Web Applications

What Should Be The Size Of The Pool?

• Pool size limiting factors

– The amount of memory

• In Java 6, the default thread stack size on Sparc is 512k for the

32-bit VM and 1024k for the 64-bit VM

Hotspot Thread Stack Numbers: http://www.oracle.com/technetwork/java/hotspotfaq-138619.html

Sunday, September 8, 13

Page 192: Troubleshooting Live Java Web Applications

What Should Be The Size Of The Pool?

• Pool size limiting factors

– The amount of memory

• In Java 6, the default thread stack size on Sparc is 512k for the

32-bit VM and 1024k for the 64-bit VM

–The number of CPUs

• Context switching could become an issue

Hotspot Thread Stack Numbers: http://www.oracle.com/technetwork/java/hotspotfaq-138619.html

Sunday, September 8, 13

Page 193: Troubleshooting Live Java Web Applications

Little’s Law

= the average response time for a request

= the approximate size for your pool

= the average arrival rate of requests

Sunday, September 8, 13

Page 194: Troubleshooting Live Java Web Applications

AFTER THE FIX

Sunday, September 8, 13

Page 195: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 196: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 197: Troubleshooting Live Java Web Applications

Image From: http://coedmagazine.files.wordpress.com/2012/08/carmelita-jeter-7.jpg

Sunday, September 8, 13

Page 198: Troubleshooting Live Java Web Applications

Image From: http://coedmagazine.files.wordpress.com/2012/08/carmelita-jeter-7.jpg

Carmelita JeterFastest Woman Alive in the

100 meter sprint

Sunday, September 8, 13

Page 199: Troubleshooting Live Java Web Applications

Image From: http://www4.pictures.zimbio.com/gi/Carmelita+Jeter+Olympics+Day+14+Athletics+G48Jqgqo2nml.jpg

My team’s 4x100 time is faster than your website.

Get that fixed!

Sunday, September 8, 13

Page 200: Troubleshooting Live Java Web Applications

LETS INVESTIGATE!

Sunday, September 8, 13

Page 201: Troubleshooting Live Java Web Applications

Application Performance Monitoring

Most application servers have an admin console which provides some

monitoring information

The quality of the admin console varies significantly between products

Sunday, September 8, 13

Page 202: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs

App Server Monitoring admin console, varies between app servers sometimes yes no

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm profiler no yes yes

JConsole JMX metrics no yes yes

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack prints thread dump of Java process

no, attaches to running process yes yes

Basic Information

Sunday, September 8, 13

Page 203: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 204: Troubleshooting Live Java Web Applications

Memory Information

Sunday, September 8, 13

Page 205: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 206: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 207: Troubleshooting Live Java Web Applications

New Relic

Application Performance Monitoring (APM) tool that monitors web

apps, mobile apps, servers, and databases

Sign up and download agent from the New Relic Website

Sunday, September 8, 13

Page 208: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 209: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 210: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 211: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 212: Troubleshooting Live Java Web Applications

Sunday, September 8, 13

Page 213: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 214: Troubleshooting Live Java Web Applications

Logs

Application, server, and database logs provide information developers

consider important for evaluating the status of the application

The quality of the logs varies significantly between products

Tools like Splunk and Loggly can help analyze logs

Sunday, September 8, 13

Page 215: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK

Logs application, app server, framework, and db logs no yes yes

App Server Monitoring admin console, varies between app servers sometimes yes no

New Relic APM solution restart app with agent

basic features: yesadv features: no

no

YourKit profiler maybe no, must pay for all features no

JVisualVm profiler no yes yes

JConsole m no yes yes

JMap/JHat prints memory map of Java process

no, attaches to running process yes yes

JStack prints thread dump of Java process

no, attaches to running process yes yes

Basic Information

Sunday, September 8, 13

Page 216: Troubleshooting Live Java Web Applications

The Application Log

Sunday, September 8, 13

Page 217: Troubleshooting Live Java Web Applications

The Application Log

Varies between applications

Sunday, September 8, 13

Page 218: Troubleshooting Live Java Web Applications

The Application Log

Varies between applications

Sunday, September 8, 13

Page 219: Troubleshooting Live Java Web Applications

The Application Log

Spring AOP

Sunday, September 8, 13

Page 220: Troubleshooting Live Java Web Applications

The Application Log

Create The Aspect

Sunday, September 8, 13

Page 221: Troubleshooting Live Java Web Applications

The Application Log

Create The Aspect

Sunday, September 8, 13

Page 222: Troubleshooting Live Java Web Applications

The Application Log

Create The Aspect

Sunday, September 8, 13

Page 223: Troubleshooting Live Java Web Applications

The Application Log

Create The Aspect

Sunday, September 8, 13

Page 224: Troubleshooting Live Java Web Applications

The Application Log

Create The Aspect

Sunday, September 8, 13

Page 225: Troubleshooting Live Java Web Applications

Application Server Log

Sunday, September 8, 13

Page 226: Troubleshooting Live Java Web Applications

Application Server Log

Information on requests

host_access_log

Sunday, September 8, 13

Page 227: Troubleshooting Live Java Web Applications

Application Server Log

Information on requests

host_access_log

Sunday, September 8, 13

Page 228: Troubleshooting Live Java Web Applications

Application Server Log

This is what the app server or framework developer considered important.

Catalina.out

Sunday, September 8, 13

Page 229: Troubleshooting Live Java Web Applications

Application Server Log

This is what the app server or framework developer considered important.

Catalina.out

Sunday, September 8, 13

Page 230: Troubleshooting Live Java Web Applications

Application Server Log

This is what the app server or framework developer considered important.

applicationContext.xml

Sunday, September 8, 13

Page 231: Troubleshooting Live Java Web Applications

Application Server Log

This is what the app server or framework developer considered important.

applicationContext.xml

Sunday, September 8, 13

Page 232: Troubleshooting Live Java Web Applications

Application Server Log

This is what the app server or framework developer considered important.

applicationContext.xml

Sunday, September 8, 13

Page 233: Troubleshooting Live Java Web Applications

Application Server Log

This is what the app server or framework developer considered important.

Catalina.out

Sunday, September 8, 13

Page 234: Troubleshooting Live Java Web Applications

MySQL Log

Sunday, September 8, 13

Page 235: Troubleshooting Live Java Web Applications

MySQL Log

The only log on by default is the error log.

Sunday, September 8, 13

Page 236: Troubleshooting Live Java Web Applications

MySQL Log

You can turn on the slow sql log.

Add the following to your /etc/my.cnf

Sunday, September 8, 13

Page 237: Troubleshooting Live Java Web Applications

MySQL Log

You can turn on the slow sql log.

Add the following to your /etc/my.cnf

Sunday, September 8, 13

Page 238: Troubleshooting Live Java Web Applications

MySQL Log

You can turn on the slow sql log.

Add the following to your /etc/my.cnf

Query Time Rows Examined

Sunday, September 8, 13

Page 239: Troubleshooting Live Java Web Applications

MySQL Log

You can turn on the slow sql log.

Add the following to your /etc/my.cnf

Query Time Rows Examined

Sunday, September 8, 13

Page 240: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 241: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 242: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 243: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 244: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 245: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 246: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 247: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 248: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 249: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 250: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 251: Troubleshooting Live Java Web Applications

USE INDEXES APPROPRIATELY

SOLUTION

Sunday, September 8, 13

Page 252: Troubleshooting Live Java Web Applications

AFTER THE FIX

Sunday, September 8, 13

Page 253: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 254: Troubleshooting Live Java Web Applications

In a Terminal

Sunday, September 8, 13

Page 255: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 256: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 257: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 258: Troubleshooting Live Java Web Applications

Tools App Response Time

DB Response Time Error Info Thread Info GC Memory

Logs

App Server Monitoring

New Relic

YourKit

JVisualVm

JConsole

JMap/JHat

JStack

Data In Tool

Sunday, September 8, 13

Page 259: Troubleshooting Live Java Web Applications

Tools Application Response Time

LogsJConsole

App Server Monitoring

JVisualVm - No Profiler

JStack

New Relic

Your Kit - No Profiler

JMap

Your Kit - With Profiler

JVisualVM - With Profiler

Basic Information

What is the impact of each tool?

Sunday, September 8, 13

Page 260: Troubleshooting Live Java Web Applications

Tools Application Response Time

Logs NoneJConsole None

App Server Monitoring None

JVisualVm - No Profiler None

JStack Low

New Relic Low

Your Kit - No Profiler High

JMap High

Your Kit - With Profiler Very High

JVisualVM - With Profiler Very High

Basic Information

Sunday, September 8, 13

Page 261: Troubleshooting Live Java Web Applications

Tools Application Response Time

Logs NoneJConsole None

App Server Monitoring None

JVisualVm - No Profiler None

JStack Low

New Relic Low

Your Kit - No Profiler High

JMap High

Your Kit - With Profiler Very High

JVisualVM - With Profiler Very High

Basic Information

Use In Production

Sunday, September 8, 13

Page 262: Troubleshooting Live Java Web Applications

Tools Application Response Time

Logs NoneJConsole None

App Server Monitoring None

JVisualVm - No Profiler None

JStack Low

New Relic Low

Your Kit - No Profiler High

JMap High

Your Kit - With Profiler Very High

JVisualVM - With Profiler Very High

Basic Information

Use In Production

Use In Development

Sunday, September 8, 13

Page 263: Troubleshooting Live Java Web Applications

Tools Application Response Time

Logs NoneJConsole None

App Server Monitoring None

JVisualVm - No Profiler None

JStack Low

New Relic Low

Your Kit - No Profiler High

JMap High

Your Kit - With Profiler Very High

JVisualVM - With Profiler Very High

Basic Information

Use In Production

Use In Development

Sunday, September 8, 13

Page 264: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK For Prod

Logs application, app server, framework, and db logs no yes yes yes

App Server Monitoring

admin console, varies between app servers sometimes yes no yes

New Relic APM Solution restart app with agent

basic features: yes

adv features: no

no yes

YourKit Profiler maybe no, must pay for all features no no

JVisualVm Profiler no yes yes basic: yesprofile: no

JConsole JMX Metrics no yes yes yes

JMap/JHat prints memory map of Java process

No, attaches to running process yes yes no

JStack prints thread dump of Java process

no, attaches to running process yes yes yes

Basic Information

Sunday, September 8, 13

Page 265: Troubleshooting Live Java Web Applications

Tools Overview Installation Is It Free Include With JDK For Prod

Logs application, app server, framework, and db logs no yes yes yes

App Server Monitoring

admin console, varies between app servers sometimes yes no yes

New Relic APM Solution restart app with agent

basic features: yes

adv features: no

no yes

YourKit Profiler maybe no, must pay for all features no no

JVisualVm Profiler no yes yes basic: yesprofile: no

JConsole JMX Metrics no yes yes yes

JMap/JHat prints memory map of Java process

No, attaches to running process yes yes no

JStack prints thread dump of Java process

no, attaches to running process yes yes yes

Basic Information

Sunday, September 8, 13

Page 266: Troubleshooting Live Java Web Applications

Image From: http://www.tbkconsult.com/blog/wp-content/uploads/2011/07/Toolbox.jpg

I encourage you to add a new tool to your tool box

Sunday, September 8, 13

Page 267: Troubleshooting Live Java Web Applications

Image From: http://www.tbkconsult.com/blog/wp-content/uploads/2011/07/Toolbox.jpg

I encourage you to add a new tool to your tool box

Add the tool sooner rather than later

Sunday, September 8, 13

Page 268: Troubleshooting Live Java Web Applications

Image From: http://www.mediaemerging.com/wp-content/uploads/2010/11/Wrong-Tool-for-the-Job2.jpg

You should learn how to use the tools before you need them

Sunday, September 8, 13

Page 270: Troubleshooting Live Java Web Applications

Learn More. Stay Connected.

Go try a new tool!

Talk to us on Twitter: @springcentralFind session replays on YouTube: spring.io/video

Sunday, September 8, 13

Page 271: Troubleshooting Live Java Web Applications

We are hiring: newrelic.com/jobs

Sunday, September 8, 13

Page 272: Troubleshooting Live Java Web Applications

http://futurestack.io

Sunday, September 8, 13


Recommended