SlideShare a Scribd company logo
Troubleshooting Real Production Problems
Ram Lakshmanan
Architect: GCeasy.io, fastThread.io, HeapHero.io
https://blog.fastthread.io/2018/12/13/how-to-troubleshoot-cpu-problems/
Troubleshooting CPU spike
Step 1: Confirm
Don‘t trust anyone
‘top’ tool is your good friend
Step 2: Identify Threads
Example:
top -H -p 31294
top –H –p {pid}
Step 3: Capture thread dumps
JDK tool. Now Open source. GUI based
option.
jVisualVMkill -3
Kill -3 <pid>
Useful when only JRE is installed
jstack (since Java 5)
jstack -l <pid> > /tmp/threadDump.txt
Few APM Tools does provide this support
APM ToolsThreadMXBean
Programmatic way to capture thread
dumps
Windows (Ctrl + Break)
https://blog.fastthread.io/2016/06/06/how-to-take-thread-dumps-7-options/
030201
070605
JDK tool. Now Open source. GUI based
option.
JMC
jcmd <pid> Thread.print >
/tmp/threadDump.txt
Jcmd (since Java 7)
04
08
Helpful during development phase
2019-02-26 17:13:23
Full thread dump Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode):
"Reconnection-1" prio=10 tid=0x00007f0442e10800 nid=0x112a waiting on condition [0x00007f042f719000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x007b3953a98> (a java.util.concurrent.locks.AbstractQueuedSynchr)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.lang.Thread.run(Thread.java:722)
:
:
1
2
3
1 Timestamp at which thread dump was triggered
2 JVM Version info
3 Thread Details - <<details in following slides>>
Anatomy of thread dump
"InvoiceThread-A996" prio=10 tid=0x00002b7cfc6fb000 nid=0x4479 runnable [0x00002b7d17ab8000]
java.lang.Thread.State: RUNNABLE
at com.buggycompany.rt.util.ItinerarySegmentProcessor.setConnectingFlight(ItinerarySegmentProcessor.java:380)
at com.buggycompany.rt.util.ItinerarySegmentProcessor.processTripType0(ItinerarySegmentProcessor.java:366)
at com.buggycompany.rt.util.ItinerarySegmentProcessor.processItineraryByTripType(ItinerarySegmentProcessor.java:254)
at com.buggycompany.rt.util.ItinerarySegmentProcessor.templateMethod(ItinerarySegmentProcessor.java:399)
at com.buggycompany.qc.gds.InvoiceGeneratedFacade.readTicketImage(InvoiceGeneratedFacade.java:252)
at com.buggycompany.qc.gds.InvoiceGeneratedFacade.doOrchestrate(InvoiceGeneratedFacade.java:151)
at com.buggycompany.framework.gdstask.BaseGDSFacade.orchestrate(BaseGDSFacade.java:32)
at com.buggycompany.framework.gdstask.BaseGDSFacade.doWork(BaseGDSFacade.java:22)
at com.buggycompany.framework.concurrent.BuggycompanyCallable.call(buggycompanyCallable.java:80)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
"InvoiceThread-A996" prio=10 tid=0x00002b7cfc6fb000 nid=0x4479 runnable [0x00002b7d17ab8000]
java.lang.Thread.State: RUNNABLE
at com.buggycompany.rt.util.ItinerarySegmentProcessor.setConnectingFlight(ItinerarySegmentProcessor.java:380)
at com.buggycompany.rt.util.ItinerarySegmentProcessor.processTripType0(ItinerarySegmentProcessor.java:366)
at com.buggycompany.rt.util.ItinerarySegmentProcessor.processItineraryByTripType(ItinerarySegmentProcessor.java:254)
at com.buggycompany.rt.util.ItinerarySegmentProcessor.templateMethod(ItinerarySegmentProcessor.java:399)
at com.buggycompany.qc.gds.InvoiceGeneratedFacade.readTicketImage(InvoiceGeneratedFacade.java:252)
at com.buggycompany.qc.gds.InvoiceGeneratedFacade.doOrchestrate(InvoiceGeneratedFacade.java:151)
at com.buggycompany.framework.gdstask.BaseGDSFacade.orchestrate(BaseGDSFacade.java:32)
at com.buggycompany.framework.gdstask.BaseGDSFacade.doWork(BaseGDSFacade.java:22)
at com.buggycompany.framework.concurrent.BuggycompanyCallable.call(buggycompanyCallable.java:80)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
1 2 3 4 5
6
7
1 Thread Name - InvoiceThread-A996
2 Priority - Can have values from 1 to 10
3
Thread Id - 0x00002b7cfc6fb000 – Unique ID assigned by JVM. It's returned by calling the Thread.getId() method.
4 Native Id - 0x4479 - This ID is highly platform dependent. On Linux, it's the pid of the thread. On Windows, it's simply the OS-level thread ID within
a process. On Mac OS X, it is said to be the native pthread_t value.
5 Address space - 0x00002b7d17ab8000 -
6 Thread State - RUNNABLE
7 Stack trace -
6 thread states
RUNNABLE
TERMINATED
NEW
TIMED_WAITING
Thread.sleep(10);
WAITING03
02
01
06
05
public void synchronized getData() {
makeDBCall();
}
BLOCKED
04
Thread 1: Runnable
Thread 2: BLOCKED
wait();
Thread 1: Runnable
Step 4: Identify lines of code causing CPU spike
Thread Ids: 31306, 31307, 31308
High CPU consuming Threads Ids reported in ‘top –H’.
Let’s look up these thread Ids in Thread dump
HexaDecimal equivalent:
• 31306  7a4a
• 31307  7a4b
• 31308  7a4c
1: package com.buggyapp.cpuspike;
2:
3: /**
4: *
5: * @author Test User
6: */
7: public class Object1 {
8:
9: public static void execute() {
10:
11: while (true) {
12:
13: doSomething();
14: }
15: }
16:
17: public static void doSomething() {
18:
19: }
20: }
Source code
‘Free’ Thread dump analysis tools
https://developer.ibm.com/javas
dk/tools/
IBM Thread & Monitor analyzerSamuraiFastThread
http://fastThread.io/ http://samuraism.jp/samurai/en/in
dex.html
Visual VM
https://visualvm.github.io/
Freely available Thread dump analysis tools
030201
04
Analysis with tool
Generated visual report
Real problem in a major trading application
Unable to create new native thread
Troubleshooting OutOfMemoryError
Major financial institution in N. America
Thread dump troubleshooting pattern: RSI
https://map.tinyurl.com/yxho6lan
Java Heap + metaspace
Physical memory
Java Heap + metaspace
Physical memory
Process-
1
Process-
2
Key: Threads are created outside heap
threads
Solution:
1. Fix thread leak
2. Increase the Thread Limits Set at
Operating System(ulimit –u)
3. Reduce Java Heap Size
4. Kills other processes
5. Increase physical memory size
6. Reduce thread stack size (-Xss).
Note: can cause StackOverflowError
OOM: Unable to create new native thread
8 types - OutOfMemoryError
Java heap space
https://blog.gceasy.io/2015/09/25/outofmemoryerror-beautiful-1-page-document/
01
GC overhead limit exceeded
02
Requested array size exceed VM limit
03
Permgen space
04
Metaspace
05
Unable to create new native thread
06
Kill process or sacrifice child
07
reason stack_trace_with_native method
08
java.lang.OutOfMemoryError: <type>
• https://tinyurl.com/yywdmvyy
• RSI Pattern – Same pattern, different problem.
Troubleshooting unresponsive app
Thread dump analysis Patterns
https://blog.fastthread.io/category/thread-dump-patterns/
Leprechaun PatternTreadmill PatternRSI Pattern
Athlete PatternTraffic Jam PatternAll Roads leads to Rome
Pattern
few more …Several Scavengers PatternAtherosclerosis Pattern
Troubleshooting Memory
problems
Enable GC Logs (always)
Till Java 8:
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<file-path>
From Java 9:
-Xlog:gc*:file=<file-path>
‘Free’ GC Log analysis tools
https://developer.ibm.com/javas
dk/tools/
IBM GC & Memory visualizerGC Viewer
https://github.com/chewiebug/G
CViewer
GCeasy
http://gceasy.io/
Google Garbage cat (cms)
https://code.google.com/archiv
e/a/eclipselabs.org/p/garbagec
at
HP Jmeter
https://h20392.www2.hpe.com/
portal/swdepot/displayProductI
nfo.do?productNumber=HPJM
ETER
Freely available Garbage collection log analysis tools
030201
0504
Heap usage graph
What is your observation?
Memory Problem
Corresponding – Reclaimed bytes chart
How to diagnose memory leak?
Capture heap dumps
jmap -dump:live,file=<file-path> <pid>
Example: jmap -dump:live,file=/opt/tmp/AddressBook-heapdump.bin 37320
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/logs/heapdump
Eclipse MAT, HeapHero
Two good tools to analyze memory leaks
Capture heap dumps
JDK tool. Now Open source. GUI based
option.
jVisualVMHeapDumpOnOutOfMemoryError
-XX:+HeapDumpOnOutOfMemoryError -
XX:HeapDumpPath=<file-path>
jmap (since Java 5)
jmap -dump:live,file=<file-path> <pid>
Few APM Tools does provide this support
APM ToolsThreadMXBean
Programmatic way to capture thread
dumps
https://blog.fastthread.io/2016/06/06/how-to-take-thread-dumps-7-options/
030201
0605
If you are using WAS, this option can be
used
IBM administrative console
jcmd <pid> GC.heap_dump <file-path>
Jcmd (since Java 7)
04
07
Micro-metrics
https://blog.gceasy.io/2019/03/13/micrometrics-to-forecast-application-performance/
Macro-Metrics
Can’t forecast scalability, availability, performance problems
CPU
RESPONSE
TIME
MEMORY
Micro-metrics: Early Indicators
Repeated Full GCs happens here
OutOfMemoryError happens here
File Descriptors
File descriptor is a handle to access: File, Pipe,
Network Connections. If count grows it’s a lead
indicator that application isn’t closing resources
properly.
Few more…
TCP/IP States, Hosts count, IOPS, ..
Thread States
If BLOCKED thread state count grows, it’s
an early indication that your application has
potential to become unresponsive
GC Throughput
Amount time application spends in processing
customer transactions vs amount of time application
spend in doing GC
Object Reclamation rate
If number of objects created in unit time
GC Latency
If pause time starts to increase, then
it’s an indication that app is suffering
from memory problems
What are Micrometrics?
https://blog.gceasy.io/2019/03/13/micrometrics-to-forecast-application-performance/
right data @ right time
GC Log
netstat vmstat
Thread Dumps
dmesg
Heap Dumps
What data to capture?
ps
top -H
Disk Usage
top
IBM Script: https://map.tinyurl.com/y4gz6o7q
Captures all of the above artifacts
Thank you my friends!
Ram Lakshmanan
ram@tier1app.com
@tier1app
https://www.linkedin.com/company/gceasy

More Related Content

PPT
Troubleshooting performanceavailabilityproblems (1)
PPTX
Major outagesmajorenteprises 2021
PPTX
How & why-memory-efficient?
PPTX
How to write memory efficient code?
PPTX
16 artifacts to capture when there is a production problem
PPTX
Micro-metrics to forecast performance tsunamis
PPTX
Lets crash-applications
PPTX
7 jvm-arguments-v1
Troubleshooting performanceavailabilityproblems (1)
Major outagesmajorenteprises 2021
How & why-memory-efficient?
How to write memory efficient code?
16 artifacts to capture when there is a production problem
Micro-metrics to forecast performance tsunamis
Lets crash-applications
7 jvm-arguments-v1

What's hot (20)

PPTX
GC Tuning & Troubleshooting Crash Course
PPTX
Lets crash-applications
PPTX
7 habits of highly effective Performance Troubleshooters
PPTX
7 jvm-arguments-Confoo
PPTX
Become a Garbage Collection Hero
PPTX
Become a GC Hero
PPTX
Don't dump thread dumps
PPTX
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
PPTX
Gc crash course (1)
PDF
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
PPT
Find bottleneck and tuning in Java Application
PDF
Embedded systems
PDF
Nine Circles of Inferno or Explaining the PostgreSQL Vacuum
PDF
Refactoring for testability c++
PPTX
Performance is a feature! - London .NET User Group
PDF
Everything you wanted to know about Stack Traces and Heap Dumps
PDF
marko_go_in_badoo
PPTX
The Art of JVM Profiling
PDF
Java In-Process Caching - Performance, Progress and Pittfalls
PDF
Cassandra is great but how do I test my application?
GC Tuning & Troubleshooting Crash Course
Lets crash-applications
7 habits of highly effective Performance Troubleshooters
7 jvm-arguments-Confoo
Become a Garbage Collection Hero
Become a GC Hero
Don't dump thread dumps
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
Gc crash course (1)
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Find bottleneck and tuning in Java Application
Embedded systems
Nine Circles of Inferno or Explaining the PostgreSQL Vacuum
Refactoring for testability c++
Performance is a feature! - London .NET User Group
Everything you wanted to know about Stack Traces and Heap Dumps
marko_go_in_badoo
The Art of JVM Profiling
Java In-Process Caching - Performance, Progress and Pittfalls
Cassandra is great but how do I test my application?
Ad

Similar to Troubleshooting real production problems (20)

PPTX
Shooting the troubles: Crashes, Slowdowns, CPU Spikes
PPTX
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
PPTX
Top-5-production-devconMunich-2023.pptx
PPTX
‘16 artifacts’ to capture when there is a production problem
PPTX
16 ARTIFACTS TO CAPTURE WHEN THERE IS A PRODUCTION PROBLEM
PDF
GDG Cloud Iasi - Docker For The Busy Developer.pdf
PPTX
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
PPTX
Hunting Performance Problems in Node.js and beyond
PPTX
Accelerating Incident Response To Production Outages
PPTX
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
PPTX
16 Critical Artifacts to Capture During Production Problems with Payara Server
PPT
Naive application development
PPTX
Top-5-Performance-JaxLondon-2023.pptx
PPTX
Debug generic process
PDF
1032 cs208 g operation system ip camera case share.v0.2
PPTX
Troubleshooting JVM Outages – 3 Fortune 500 case studies
PPTX
Don't dump thread dumps
PPT
jvm goes to big data
PPT
A Life of breakpoint
PPTX
Top 5 Java Performance Problems Presentation!
Shooting the troubles: Crashes, Slowdowns, CPU Spikes
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Top-5-production-devconMunich-2023.pptx
‘16 artifacts’ to capture when there is a production problem
16 ARTIFACTS TO CAPTURE WHEN THERE IS A PRODUCTION PROBLEM
GDG Cloud Iasi - Docker For The Busy Developer.pdf
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Hunting Performance Problems in Node.js and beyond
Accelerating Incident Response To Production Outages
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
16 Critical Artifacts to Capture During Production Problems with Payara Server
Naive application development
Top-5-Performance-JaxLondon-2023.pptx
Debug generic process
1032 cs208 g operation system ip camera case share.v0.2
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Don't dump thread dumps
jvm goes to big data
A Life of breakpoint
Top 5 Java Performance Problems Presentation!
Ad

More from Tier1 app (20)

PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PDF
Virtual Threads in Java: A New Dimension of Scalability and Performance
PDF
Troubleshooting Virtual Threads in Java!
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
PPTX
Key Challenges in Troubleshooting Customer On-Premise Applications
PPTX
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
PPTX
GC Tuning: A Masterpiece in Performance Engineering
PPTX
Troubleshooting JVM Outages – 3 Fortune 500 Case Studies
PPTX
How to Troubleshoot 9 Types of OutOfMemoryError
PPTX
Not So Common Memory Leaks in Java Webinar
PPTX
Common Memory Leaks in Java and How to Fix Them
PPTX
7 Micro-Metrics That Predict Production Outages in Performance Labs Webinar
PPTX
Mastering Thread Dump Analysis: 9 Tips & Tricks
PPTX
How to Check and Optimize Memory Size for Better Application Performance
PPTX
TroubleshootingJVMOutages-3CaseStudies (1).pptx
PPTX
TroubleshootingJVMOutages-3CaseStudies.pptx
PPTX
Major Outages in Major Enterprises Payara Conference
PPTX
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
PPTX
Top-5-java-perf-problems-jax_mainz_2024.pptx
PPTX
Effectively Troubleshoot 9 Types of OutOfMemoryError
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Virtual Threads in Java: A New Dimension of Scalability and Performance
Troubleshooting Virtual Threads in Java!
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Key Challenges in Troubleshooting Customer On-Premise Applications
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
GC Tuning: A Masterpiece in Performance Engineering
Troubleshooting JVM Outages – 3 Fortune 500 Case Studies
How to Troubleshoot 9 Types of OutOfMemoryError
Not So Common Memory Leaks in Java Webinar
Common Memory Leaks in Java and How to Fix Them
7 Micro-Metrics That Predict Production Outages in Performance Labs Webinar
Mastering Thread Dump Analysis: 9 Tips & Tricks
How to Check and Optimize Memory Size for Better Application Performance
TroubleshootingJVMOutages-3CaseStudies (1).pptx
TroubleshootingJVMOutages-3CaseStudies.pptx
Major Outages in Major Enterprises Payara Conference
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Top-5-java-perf-problems-jax_mainz_2024.pptx
Effectively Troubleshoot 9 Types of OutOfMemoryError

Recently uploaded (20)

PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
System and Network Administraation Chapter 3
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PDF
top salesforce developer skills in 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
AI in Product Development-omnex systems
PPTX
ai tools demonstartion for schools and inter college
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PPT
Introduction Database Management System for Course Database
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ManageIQ - Sprint 268 Review - Slide Deck
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
System and Network Administraation Chapter 3
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
top salesforce developer skills in 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
AI in Product Development-omnex systems
ai tools demonstartion for schools and inter college
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Design an Analysis of Algorithms II-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Operating system designcfffgfgggggggvggggggggg
Introduction Database Management System for Course Database
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...

Troubleshooting real production problems

  • 1. Troubleshooting Real Production Problems Ram Lakshmanan Architect: GCeasy.io, fastThread.io, HeapHero.io
  • 3. Step 1: Confirm Don‘t trust anyone ‘top’ tool is your good friend
  • 4. Step 2: Identify Threads Example: top -H -p 31294 top –H –p {pid}
  • 5. Step 3: Capture thread dumps JDK tool. Now Open source. GUI based option. jVisualVMkill -3 Kill -3 <pid> Useful when only JRE is installed jstack (since Java 5) jstack -l <pid> > /tmp/threadDump.txt Few APM Tools does provide this support APM ToolsThreadMXBean Programmatic way to capture thread dumps Windows (Ctrl + Break) https://blog.fastthread.io/2016/06/06/how-to-take-thread-dumps-7-options/ 030201 070605 JDK tool. Now Open source. GUI based option. JMC jcmd <pid> Thread.print > /tmp/threadDump.txt Jcmd (since Java 7) 04 08 Helpful during development phase
  • 6. 2019-02-26 17:13:23 Full thread dump Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode): "Reconnection-1" prio=10 tid=0x00007f0442e10800 nid=0x112a waiting on condition [0x00007f042f719000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x007b3953a98> (a java.util.concurrent.locks.AbstractQueuedSynchr) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.lang.Thread.run(Thread.java:722) : : 1 2 3 1 Timestamp at which thread dump was triggered 2 JVM Version info 3 Thread Details - <<details in following slides>> Anatomy of thread dump "InvoiceThread-A996" prio=10 tid=0x00002b7cfc6fb000 nid=0x4479 runnable [0x00002b7d17ab8000] java.lang.Thread.State: RUNNABLE at com.buggycompany.rt.util.ItinerarySegmentProcessor.setConnectingFlight(ItinerarySegmentProcessor.java:380) at com.buggycompany.rt.util.ItinerarySegmentProcessor.processTripType0(ItinerarySegmentProcessor.java:366) at com.buggycompany.rt.util.ItinerarySegmentProcessor.processItineraryByTripType(ItinerarySegmentProcessor.java:254) at com.buggycompany.rt.util.ItinerarySegmentProcessor.templateMethod(ItinerarySegmentProcessor.java:399) at com.buggycompany.qc.gds.InvoiceGeneratedFacade.readTicketImage(InvoiceGeneratedFacade.java:252) at com.buggycompany.qc.gds.InvoiceGeneratedFacade.doOrchestrate(InvoiceGeneratedFacade.java:151) at com.buggycompany.framework.gdstask.BaseGDSFacade.orchestrate(BaseGDSFacade.java:32) at com.buggycompany.framework.gdstask.BaseGDSFacade.doWork(BaseGDSFacade.java:22) at com.buggycompany.framework.concurrent.BuggycompanyCallable.call(buggycompanyCallable.java:80) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722)
  • 7. "InvoiceThread-A996" prio=10 tid=0x00002b7cfc6fb000 nid=0x4479 runnable [0x00002b7d17ab8000] java.lang.Thread.State: RUNNABLE at com.buggycompany.rt.util.ItinerarySegmentProcessor.setConnectingFlight(ItinerarySegmentProcessor.java:380) at com.buggycompany.rt.util.ItinerarySegmentProcessor.processTripType0(ItinerarySegmentProcessor.java:366) at com.buggycompany.rt.util.ItinerarySegmentProcessor.processItineraryByTripType(ItinerarySegmentProcessor.java:254) at com.buggycompany.rt.util.ItinerarySegmentProcessor.templateMethod(ItinerarySegmentProcessor.java:399) at com.buggycompany.qc.gds.InvoiceGeneratedFacade.readTicketImage(InvoiceGeneratedFacade.java:252) at com.buggycompany.qc.gds.InvoiceGeneratedFacade.doOrchestrate(InvoiceGeneratedFacade.java:151) at com.buggycompany.framework.gdstask.BaseGDSFacade.orchestrate(BaseGDSFacade.java:32) at com.buggycompany.framework.gdstask.BaseGDSFacade.doWork(BaseGDSFacade.java:22) at com.buggycompany.framework.concurrent.BuggycompanyCallable.call(buggycompanyCallable.java:80) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722) 1 2 3 4 5 6 7 1 Thread Name - InvoiceThread-A996 2 Priority - Can have values from 1 to 10 3 Thread Id - 0x00002b7cfc6fb000 – Unique ID assigned by JVM. It's returned by calling the Thread.getId() method. 4 Native Id - 0x4479 - This ID is highly platform dependent. On Linux, it's the pid of the thread. On Windows, it's simply the OS-level thread ID within a process. On Mac OS X, it is said to be the native pthread_t value. 5 Address space - 0x00002b7d17ab8000 - 6 Thread State - RUNNABLE 7 Stack trace -
  • 8. 6 thread states RUNNABLE TERMINATED NEW TIMED_WAITING Thread.sleep(10); WAITING03 02 01 06 05 public void synchronized getData() { makeDBCall(); } BLOCKED 04 Thread 1: Runnable Thread 2: BLOCKED wait(); Thread 1: Runnable
  • 9. Step 4: Identify lines of code causing CPU spike Thread Ids: 31306, 31307, 31308 High CPU consuming Threads Ids reported in ‘top –H’. Let’s look up these thread Ids in Thread dump HexaDecimal equivalent: • 31306  7a4a • 31307  7a4b • 31308  7a4c
  • 10. 1: package com.buggyapp.cpuspike; 2: 3: /** 4: * 5: * @author Test User 6: */ 7: public class Object1 { 8: 9: public static void execute() { 10: 11: while (true) { 12: 13: doSomething(); 14: } 15: } 16: 17: public static void doSomething() { 18: 19: } 20: } Source code
  • 11. ‘Free’ Thread dump analysis tools https://developer.ibm.com/javas dk/tools/ IBM Thread & Monitor analyzerSamuraiFastThread http://fastThread.io/ http://samuraism.jp/samurai/en/in dex.html Visual VM https://visualvm.github.io/ Freely available Thread dump analysis tools 030201 04
  • 13. Real problem in a major trading application
  • 14. Unable to create new native thread Troubleshooting OutOfMemoryError
  • 15. Major financial institution in N. America Thread dump troubleshooting pattern: RSI https://map.tinyurl.com/yxho6lan
  • 16. Java Heap + metaspace Physical memory Java Heap + metaspace Physical memory Process- 1 Process- 2 Key: Threads are created outside heap threads Solution: 1. Fix thread leak 2. Increase the Thread Limits Set at Operating System(ulimit –u) 3. Reduce Java Heap Size 4. Kills other processes 5. Increase physical memory size 6. Reduce thread stack size (-Xss). Note: can cause StackOverflowError OOM: Unable to create new native thread
  • 17. 8 types - OutOfMemoryError Java heap space https://blog.gceasy.io/2015/09/25/outofmemoryerror-beautiful-1-page-document/ 01 GC overhead limit exceeded 02 Requested array size exceed VM limit 03 Permgen space 04 Metaspace 05 Unable to create new native thread 06 Kill process or sacrifice child 07 reason stack_trace_with_native method 08 java.lang.OutOfMemoryError: <type>
  • 18. • https://tinyurl.com/yywdmvyy • RSI Pattern – Same pattern, different problem. Troubleshooting unresponsive app
  • 19. Thread dump analysis Patterns https://blog.fastthread.io/category/thread-dump-patterns/ Leprechaun PatternTreadmill PatternRSI Pattern Athlete PatternTraffic Jam PatternAll Roads leads to Rome Pattern few more …Several Scavengers PatternAtherosclerosis Pattern
  • 21. Enable GC Logs (always) Till Java 8: -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<file-path> From Java 9: -Xlog:gc*:file=<file-path>
  • 22. ‘Free’ GC Log analysis tools https://developer.ibm.com/javas dk/tools/ IBM GC & Memory visualizerGC Viewer https://github.com/chewiebug/G CViewer GCeasy http://gceasy.io/ Google Garbage cat (cms) https://code.google.com/archiv e/a/eclipselabs.org/p/garbagec at HP Jmeter https://h20392.www2.hpe.com/ portal/swdepot/displayProductI nfo.do?productNumber=HPJM ETER Freely available Garbage collection log analysis tools 030201 0504
  • 24. What is your observation?
  • 27. How to diagnose memory leak? Capture heap dumps jmap -dump:live,file=<file-path> <pid> Example: jmap -dump:live,file=/opt/tmp/AddressBook-heapdump.bin 37320 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/logs/heapdump Eclipse MAT, HeapHero Two good tools to analyze memory leaks
  • 28. Capture heap dumps JDK tool. Now Open source. GUI based option. jVisualVMHeapDumpOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError - XX:HeapDumpPath=<file-path> jmap (since Java 5) jmap -dump:live,file=<file-path> <pid> Few APM Tools does provide this support APM ToolsThreadMXBean Programmatic way to capture thread dumps https://blog.fastthread.io/2016/06/06/how-to-take-thread-dumps-7-options/ 030201 0605 If you are using WAS, this option can be used IBM administrative console jcmd <pid> GC.heap_dump <file-path> Jcmd (since Java 7) 04 07
  • 30. Macro-Metrics Can’t forecast scalability, availability, performance problems CPU RESPONSE TIME MEMORY
  • 31. Micro-metrics: Early Indicators Repeated Full GCs happens here OutOfMemoryError happens here
  • 32. File Descriptors File descriptor is a handle to access: File, Pipe, Network Connections. If count grows it’s a lead indicator that application isn’t closing resources properly. Few more… TCP/IP States, Hosts count, IOPS, .. Thread States If BLOCKED thread state count grows, it’s an early indication that your application has potential to become unresponsive GC Throughput Amount time application spends in processing customer transactions vs amount of time application spend in doing GC Object Reclamation rate If number of objects created in unit time GC Latency If pause time starts to increase, then it’s an indication that app is suffering from memory problems What are Micrometrics? https://blog.gceasy.io/2019/03/13/micrometrics-to-forecast-application-performance/
  • 33. right data @ right time
  • 34. GC Log netstat vmstat Thread Dumps dmesg Heap Dumps What data to capture? ps top -H Disk Usage top IBM Script: https://map.tinyurl.com/y4gz6o7q Captures all of the above artifacts
  • 35. Thank you my friends! Ram Lakshmanan ram@tier1app.com @tier1app https://www.linkedin.com/company/gceasy