Analyzing Memory Errors in Production
Markus Weninger
Johannes Kepler University Linz, Austria
Institute for System Software
WHO ARE WE?
Fixing Memory Problems In Production 2
WHO ARE WE?
Fixing Memory Problems In Production 2
WHO ARE WE?
Fixing Memory Problems In Production 2
WHO ARE WE?
Fixing Memory Problems In Production 2
WHO ARE WE?
Fixing Memory Problems In Production 2
WHO ARE WE?
Fixing Memory Problems In Production 2
WHO ARE WE?
For what?
To find and fix memory anomalies!
Fixing Memory Problems In Production 2
MOTIVATION
3 Fixing Memory Problems In Production
MOTIVATION
3 Fixing Memory Problems In Production
Jake
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
MOTIVATION
3 Fixing Memory Problems In Production
Jake
July
4 Fixing Memory Problems In Production
* not actually Jake
4 Fixing Memory Problems In Production
Why is my program crashing?
* not actually Jake
4 Fixing Memory Problems In Production
Why is my program crashing?
* not actually Jake
Let‘s try a
memory
analysis tool!
PROBLEM
5 Fixing Memory Problems In Production
PROBLEM
5 Fixing Memory Problems In Production
PROBLEM
5 Fixing Memory Problems In Production
PROBLEM
5 Fixing Memory Problems In Production
I am new to
all of this!
PROBLEM
5 Fixing Memory Problems In Production
I am new to all of this!
What should
I look for?
PROBLEM
5 Fixing Memory Problems In Production
I am new to all of this!
What should I look for?
When to use
which feature?
PROBLEM
5 Fixing Memory Problems In Production
I am new to all of this!
What should I look for?
When to use which feature?
<another question about memory
analysis> ...
POLL TIME
6 Fixing Memory Problems In Production
POLL TIME
6 Fixing Memory Problems In Production
0 1 2 3 4 5 6
Used a memory analysis tool before
Manually took a heap dump Knows what trace-based memory analysis is
Could describe what a
dominator tree is
Dummy Series 1 Dummy Series 2 Dummy Series 3
USERS NEED GUIDANCE
Fixing Memory Problems In Production 7
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
GC root
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
GC root
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
GC root
... ... ... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
GC root
... ... ... ...
...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
GC root
... ... ... ...
...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
GC root GC root
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
GC root GC root
1 Mio. 10,000
10,000 10,000
1 Mio.
1 Mio.
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
GC root GC root
1 Mio. 10,000
10,000 10,000
1 Mio.
1 Mio.
... ...
MEMORY ANALYSIS 101
Fixing Memory Problems In Production 8
Top-down analysis Bottom-up analysis
GC root
... ... ... ...
Which single object / GC root keeps the most other objects alive?
GC root GC root
1 Mio. 10,000
10,000 10,000
1 Mio.
1 Mio.
...
Analyze why a certain group of objects accumulates over time
...
DOMINATOR TREE
Fixing Memory Problems In Production 9
GC Roots
L1 L2
N1 N2 N3 N4 N5
D1 D2 D3 D4 D5
D6 D7 D8
N6 N7 N8 N9
N10
Object Reference Graph
DOMINATOR TREE
Fixing Memory Problems In Production 9
GC Roots
L1 L2
N1 N2 N3 N4 N5
D1 D2 D3 D4 D5
D6 D7 D8
N6 N7 N8 N9
N10
Dom. Tree Root
L1 L2
N1 N2 N3 N4 N5 D1
D2 D3 D4 D5
D6 D7
D8
N6 N7 N8 N9
N10
Object Reference Graph Dominator Tree
DOMINATOR TREE
Fixing Memory Problems In Production 10
GC Roots
L1 L2
N1 N2 N3 N4 N5
D1 D2 D3 D4 D5
D6 D7 D8
N6 N7 N8 N9
N10
Dom. Tree Root
L1 L2
N1 N2 N3 N4 N5 D1
D2 D3 D4 D5
D6 D7
D8
N6 N7 N8 N9
N10
Object Reference Graph Dominator Tree
DOMINATOR TREE
Fixing Memory Problems In Production 10
GC Roots
L1 L2
N1 N2 N3 N4 N5
D1 D2 D3 D4 D5
D6 D7 D8
N6 N7 N8 N9
N10
Dom. Tree Root
L1 L2
N1 N2 N3 N4 N5 D1
D2 D3 D4 D5
D6 D7
D8
N6 N7 N8 N9
N10
Object Reference Graph Dominator Tree
What happens if we could free L1?
DOMINATOR TREE
Fixing Memory Problems In Production 11
GC Roots
L1 L2
N1 N2 N3 N4 N5
D1 D2 D3 D4 D5
D6 D7 D8
N6 N7 N8 N9
N10
Dom. Tree Root
L1 L2
N1 N2 N3 N4 N5 D1
D2 D3 D4 D5
D6 D7
D8
N6 N7 N8 N9
N10
Object Reference Graph Dominator Tree
These can be
collected too
Fixing Memory Problems In Production 12
Fixing Memory Problems In Production 12
Thanks Markus, but that
seems like a lot to learn...
Fixing Memory Problems In Production 12
Thanks Markus, but that
seems like a lot to learn...
Fixing Memory Problems In Production 12
Thanks Markus, but that seems like a lot to learn...
Okay, let us try to
improve that in AntTracks
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X()
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X()
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X()
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y()
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z()
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y()
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace
file
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1 Heap 2
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1 Heap 2 Heap n
…
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1 Heap 2 Heap n
…
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1 Heap 2 Heap n
…
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1 Heap 2 Heap n
…
ANTTRACKS SYSTEM OVERVIEW
Fixing Memory Problems In Production 13
AntTracks VM Application t
M ut at or phase M ut . phase GC pha s e
new X() new Y() new Z() new Y()
move move move
new Y() new Z()
Trace file
AntTracks Analyzer Memory anomaly detection
Memory leak analysis
Heap 1 Heap 2 Heap n
…
GUIDED EXPLORATION
Fixing Memory Problems In Production 14
GUIDED EXPLORATION
Fixing Memory Problems In Production 14
Detection describes the task of automatically detecting a potential problem, i.e.,
a suspicious pattern.
GUIDED EXPLORATION
Fixing Memory Problems In Production 14
Detection describes the task of automatically detecting a potential problem, i.e., a suspicious pattern.
Highlighting the relevant region on the UI helps users to understand where the
automatically gained insight can be found if the view was inspected manually.
GUIDED EXPLORATION
Fixing Memory Problems In Production 14
Detection describes the task of automatically detecting a potential problem, i.e., a suspicious pattern.
Highlighting the relevant region on the UI helps users to understand where the automatically gained insight can be found if the view was inspected manually.
Explanation of the highlighted visualization helps users to interpret it and
explains concepts that are needed for this interpretation.
GUIDED EXPLORATION
Fixing Memory Problems In Production 14
Detection describes the task of automatically detecting a potential problem, i.e., a suspicious pattern.
Highlighting the relevant region on the UI helps users to understand where the automatically gained insight can be found if the view was inspected manually.
Explanation of the highlighted visualization helps users to interpret it and explains concepts that are needed for this interpretation.
Suggestions on which steps could / should be taken next make it easier for the
user to understand what operations are possible and why they might be useful.
GUIDED EXPLORATION
Fixing Memory Problems In Production 14
Detection describes the task of automatically detecting a potential problem, i.e., a suspicious pattern.
Highlighting the relevant region on the UI helps users to understand where the automatically gained insight can be found if the view was inspected manually.
Explanation of the highlighted visualization helps users to interpret it and explains concepts that are needed for this interpretation.
Suggestions on which steps could / should be taken next make it easier for the
user to understand what operations are possible and why they might be useful.
DEMO: EASYTRAVEL
Fixing Memory Problems In Production 15
DEMO: OVERVIEW
Fixing Memory Problems In Production 16
DEMO: OVERVIEW
(1) DETECTION + (2) HIGHLIGHTING
Fixing Memory Problems In Production 17
DEMO: OVERVIEW
(3) EXPLANATION + (4) SUGGESTION
Fixing Memory Problems In Production 18
DEMO: EVOLUTION
Fixing Memory Problems In Production 19
DEMO: EVOLUTION
Fixing Memory Problems In Production 20
DEMO: EVOLUTION
Fixing Memory Problems In Production 20
Date objects allocated in the constructor of Base are the major suspects for a memory leak since about 30% of the overall heap growth is accounted to them.
Inspect who keeps them alive.
DEMO: GRAPH VIEW
Fixing Memory Problems In Production 21
DEMO: GRAPH VIEW
Fixing Memory Problems In Production 22
DEMO: GRAPH VIEW
Fixing Memory Problems In Production 23
DEMO: GRAPH VIEW
Fixing Memory Problems In Production 23
DEMO: GRAPH VIEW
Fixing Memory Problems In Production 23
Too many ArrayList<Location>
are added here.
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 24
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 25
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 26
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 27
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 27
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 27
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 27
ANOTHER DEMO: FINAGLE-HTTP
Fixing Memory Problems In Production 27
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request)
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
val h = { rep: http.Response =>
totalLength += rep.content.length }
for (i <- 0 until NUM_REQUESTS {
Await.result(response.onSuccess(h)) }
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
val h = { rep: http.Response =>
totalLength += rep.content.length }
for (i <- 0 until NUM_REQUESTS {
Await.result(response.onSuccess(h)) }
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
val h = { rep: http.Response =>
totalLength += rep.content.length }
for (i <- 0 until NUM_REQUESTS {
Await.result(response.onSuccess(h)) }
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
val h = { rep: http.Response =>
totalLength += rep.content.length }
for (i <- 0 until NUM_REQUESTS {
Await.result(response.onSuccess(h)) }
Fixing Memory Problems In Production 28
DEMO: FINAGLE-HTTP
val response: Future[http.Response] = client(request) for (i <- 0 until NUM_REQUESTS) {
Await.result(response.onSuccess { rep: http.Response =>
totalLength += rep.content.length })
}
val h = { rep: http.Response =>
totalLength += rep.content.length }
for (i <- 0 until NUM_REQUESTS {
Await.result(response.onSuccess(h)) }
Fixing Memory Problems In Production 28
TAKE-AWAYS
Fixing Memory Problems In Production 29
TAKE-AWAYS
Fixing Memory Problems In Production 29
Memory Analysis
Top-down Bottom-up Heap dumps
Trace-based
... and 100 other things
TAKE-AWAYS
Fixing Memory Problems In Production 29
Memory Analysis Problem
Top-down Bottom-up Heap dumps
Trace-based
... and 100 other things
New users need guidance to get
started faster It is not enough to
„throw tools at them“
TAKE-AWAYS
Fixing Memory Problems In Production 29
Memory Analysis Problem Guided Exploration
Top-down Bottom-up Heap dumps
Trace-based
... and 100 other things
New users need guidance to get
started faster It is not enough to
„throw tools at them“
Detection Highlighting
Explanation
Suggestion
TAKE-AWAYS
Fixing Memory Problems In Production 29
Memory Analysis Problem Guided Exploration
Top-down Bottom-up Heap dumps
Trace-based
... and 100 other things
New users need guidance to get
started faster It is not enough to
„throw tools at them“
Detection Highlighting
Explanation Suggestion
Markus Weninger
Johannes Kepler University
Linz, Austria
markus.weninger@jku.at
http://mevss.jku.at/AntTracks
http://bit.ly/weninger_ssw
Additional Notes
Some icons made by Freepik & Smashicons from https://www.flaticon.com
Some photos made by bruce mars and Isaque Pereira from Pexels
Fixing Memory Problems In Production 30