-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
386 lines (371 loc) · 13.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>reveal.js</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/moon.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/monokai.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<style>
.svg {
width: 10rem;
height: 10rem;
color: #fff;
display: inline-block
}
.svg.small {
width: 3rem;
height: 3rem;
color: #fff;
display: inline-block
}
.svg svg {
fill: currentColor;
}
.reveal section.img_container {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.reveal pre {
width: 100%;
}
.reveal pre code {
max-height: 100%;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>NodeJS performance analysis</h1>
</section>
<section>
<h2>Christian Hennig</h2>
ScalaHacker @ inoio.de
<div>
<div style="float:left">
<div class="svg"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44 42">
<path d="M21.6 0C9.7 0 0 9.6 0 21.5 0 31 6.2 39.1 14.8 42c1.1.2 1.4-.5 1.4-1v-4c-6 1.3-7.3-2.5-7.3-2.5-1-2.5-2.4-3.2-2.4-3.2-2-1.3.1-1.3.1-1.3 2.2.2 3.3 2.2 3.3 2.2 1.9 3.3 5.1 2.3 6.3 1.8.2-1.4.8-2.3 1.4-2.9-4.8-.5-9.9-2.4-9.9-10.6 0-2.4.8-4.3 2.2-5.8-.2-.5-1-2.7.2-5.7 0 0 1.8-.6 6 2.2 1.7-.5 3.6-.7 5.4-.7 1.8 0 3.7.2 5.4.7C31.2 8.4 33 8.9 33 8.9c1.2 3 .4 5.2.2 5.7 1.4 1.5 2.2 3.4 2.2 5.8 0 8.3-5.1 10.1-9.9 10.6.8.7 1.5 2 1.5 4v5.9c0 .6.3 1.2 1.4 1C37 39 43.2 31 43.2 21.5 43.3 9.6 33.6 0 21.6 0z"></path>
</svg> </div>
<span>caraboides</span><br />
<div class="svg"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 42">
<path d="M21 0C9.4 0 0 9.4 0 21s9.4 21 21 21 21-9.4 21-21S32.6 0 21 0zm10.6 16.9c.3 7.1-5 15-14.3 15-2.8 0-5.5-.8-7.7-2.3 2.7.3 5.3-.4 7.4-2.1-2.2 0-4.1-1.5-4.7-3.5.8.2 1.6.1 2.3-.1-2.4-.5-4.1-2.7-4-5 .7.4 1.5.6 2.3.6-2.2-1.5-2.9-4.5-1.6-6.7 2.5 3 6.2 5 10.4 5.3-.7-3.1 1.7-6.2 4.9-6.2 1.4 0 2.8.6 3.7 1.6 1.1-.2 2.2-.6 3.2-1.2-.4 1.2-1.2 2.2-2.2 2.8 1-.1 2-.4 2.9-.8-.7 1-1.6 1.9-2.6 2.6z"></path>
</svg> </div>
<span>caraboides</span>
</div>
<div style="float:right">
<img src="./assets/christian.jpg" />
</div>
</div>
</section>
<section>
<h2>Disclaimer</h2>
<p>I'll show you what I've tried to solve my problem.</p>
<b class="fragment">But I failed! I did not find the solution for my problem.</b>
<p class="fragment">Maybe you have an idea. ;-)</p>
</section>
<section>
<h2>Overview</h2>
<ul>
<li class="fragment">What's my problem</li>
<li class="fragment">How to find bottlenecks with monitoring</li>
<li class="fragment">How to get and analyze CPU profiles</li>
<li class="fragment">How to get and analyze heap dumps</li>
<li class="fragment">Tracing with DataDog</li>
</ul>
</ul>
</section>
<section>
<h1>Taschenherz</h1>
</section>
<section>
<h1>Problem</h1>
<h2 class="fragment">Service Response Time > 1sec</h2>
<h2 class="fragment">Nginx aborts Requests after 1 sec</h2>
</section>
<section>
<section data-background-image="./assets/k9.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k8.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k7.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k6.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k5.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k4.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k3.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k2.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k1.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k0.svg" data-background-size="contain" data-transition="none"></section>
<section data-background-image="./assets/k.svg" data-background-size="contain" data-transition="none"></section>
</section>
<section>
<h3>Step 1</h3>
<ul>
<li class="fragment">Steady and reproducible environment</li>
<li class="fragment">Documentation of every step: idea, change, impact</li>
<li class="fragment">Periodic and automatic tests to reproduce your issue</li>
<li class="fragment">I use Gatling</li>
<img class="fragment" src="./assets/gatling.png">
</ul>
</section>
<section>
<h3>Step 2</h3>
<ul>
<li class="fragment">Add monitoring to your NodeJS application</li>
<li class="fragment">System which saves and displays your monitoring data</li>
<li class="fragment">Prometheus + Grafana</li>
<li class="fragment">Don't use average! Use percentiles like 95p to see spikes!</li>
<li class="fragment">npm i --save express-prom-bundle <b>5.1.0</b></li>
<pre class="fragment">
<code data-trim data-noescape>
const metricsMiddleware = require('express-prom-bundle')({
percentiles: [ 0.5, 0.75, 0.9, 0.95, 0.99],
metricType: 'summary',
maxAgeSeconds: 300,
ageBuckets: 5
})
const app = express()
app.use(metricsMiddleware)
</code>
</pre>
</ul>
</section>
<section>
<img src="./assets/monitor-req-count.png">
<img src="./assets/monitor-req-p95.png">
</section>
<section>
<h3>Step 3</h3>
<ul>
<li class="fragment">Add more monitoring</li>
<li class="fragment">Monitor critical code paths</li>
<li class="fragment">Calls to other Services</li>
<li class="fragment">CPU intensive paths, e.g. json-parsing or crypto </li>
</ul>
</section>
<section>
<pre>
<code data-trim data-noescape>
const promClient = require('prom-client')
const externalCallMonitor = new promClient.Summary({
name: 'external_call_duration_ms',
percentiles: [0.5, 0.75, 0.9, 0.95, 0.99],
maxAgeSeconds: 300,
ageBuckets: 5
})
</code>
</pre>
<pre class="fragment">
<code data-trim data-noescape>
const requeststart = process.hrtime()
request({uri: "http://reco-server/reco?pid=1"}).
then((body) => {
const requestduration = process.hrtime(requeststart)
externalCallMonitor.observe(requestduration[1] / 1000000)
})
</code>
</pre>
</section>
<section>
<img src="./assets/monitor-recoservice.png">
<img src="./assets/monitor-db.png">
<img src="./assets/monitor-jsx.png">
</section>
<section>
<h3>Step 4</h3>
<ul>
<li class="fragment">Add more monitoring</li>
<li class="fragment">Monitor the whole business code path</li>
<li class="fragment">From request handling to writing the response</li>
</ul>
</section>
<section>
<pre >
<code data-trim data-noescape>
const promClient = require('prom-client')
const businessLogicMonitor = new promClient.Summary({
name: 'business_logic_duration_ms',
percentiles: [0.5, 0.75, 0.9, 0.95, 0.99],
maxAgeSeconds: 300,
ageBuckets: 5
})
</code>
</pre>
<pre class="fragment">
<code data-trim data-noescape>
router.get('/recos', (req, res) => {
const businessLogicStart = process.hrtime()
businessLogic(req.body) // Transform Data, Call 3 external Services
.then((html) => {
const businessDuration = process.hrtime(businessLogicStart)
businessLogicMonitor.observe(businessDuration[1] / 1000000)
res.send(html)
})
})
</code>
</pre>
</section>
<section>
<img src="./assets/monitor-businnes.png">
</section>
<section>
<h3>Step 5</h3>
<ul>
<li class="fragment">CPU Profiling</li>
<li class="fragment">node --prof app.js | Was not an option</li>
<li class="fragment">npm i --save v8-profiler-node8</li>
</ul>
</section>
<section>
<pre >
<code data-trim data-noescape>
const express = require('express')
const router = express.Router()
const profiler = require("v8-profiler-node8")
router.get('/cpuprofile', (req, res) => {
const id = Date.now() + ".profile"
profiler.startProfiling(id)
// stop profiling in n seconds and exit
setTimeout(() => {
res.set('Content-Type', 'application/json-home')
res.json(profiler.stopProfiling(id))
profiler.deleteAllProfiles()
}, 10000)
})
module.exports = router
</code>
</pre>
</section>
<section>
Chrome analysis
</section>
<section>
<h3>Step 6</h3>
<ul>
<li class="fragment">Heap Dumps</li>
<li class="fragment">npm i --save heapdump</li>
</ul>
</section>
<section>
<pre >
<code data-trim data-noescape>
const express = require('express')
const router = express.Router()
const heapdump = require('heapdump')
const fileSystem = require('fs')
router.get('/heapdump', (req, response) => {
heapdump.writeSnapshot(function(err, filename) {
var stat = fileSystem.statSync(filename);
response.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filename);
readStream.pipe(response);
});
})
module.exports = router
</code>
</pre>
</section>
<section>
Chrome analysis
</section>
<section>
<h3>Step 7</h3>
<ul>
<li class="fragment">Add more monitoring</li>
<li class="fragment">Monitor GarbageCollection and Internals of nodes</li>
<li class="fragment">npm i --save prometheus-gc-stats</li>
</ul>
</section>
<section>
<pre >
<code data-trim data-noescape>
const prometheus = require('prom-client')
prometheus.collectDefaultMetrics()
const gcStats = require('prometheus-gc-stats')
const startGcStats = gcStats(prometheus.register)
startGcStats();
</code>
</pre>
</section>
<section>
Demo Board
</section>
<section>
<h3>Step 8</h3>
<ul>
<li class="fragment">Tracing with DataDog</li>
<li class="fragment">npm i --save dd-trace</li>
<pre class="fragment">
<code data-trim data-noescape>
const tracer = require('dd-trace').init()
// enable and configure postgresql integration
tracer.use('pg', {
service: 'pg-cluster'
})
// enable and configure express integration
tracer.use('express', {
service: 'express-cluster'
})
</code>
</pre>
</ul>
</section>
<section>
<h1>
DD-Demo
</h1>
</section>
<section>
<h1>My next Steps</h1>
<ul>
<li class="fragment">Local setup to reproduce the issue: docker-compose + blockade</li>
<li class="fragment">Take a deeper look into tcp.connect, [http|tcp]_keep_alive</li>
<li class="fragment">Rewrite in scala: service issue or environment issue?</li>
</ul>
</section>
<section>
<h1>Questions ?</h1>
<h1>Ideas ?</h1>
<div>
Slides: https://github.com/inoio/node-perf-talk
</div>
<div>
<div class="small svg"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 42">
<path d="M21 0C9.4 0 0 9.4 0 21s9.4 21 21 21 21-9.4 21-21S32.6 0 21 0zm10.6 16.9c.3 7.1-5 15-14.3 15-2.8 0-5.5-.8-7.7-2.3 2.7.3 5.3-.4 7.4-2.1-2.2 0-4.1-1.5-4.7-3.5.8.2 1.6.1 2.3-.1-2.4-.5-4.1-2.7-4-5 .7.4 1.5.6 2.3.6-2.2-1.5-2.9-4.5-1.6-6.7 2.5 3 6.2 5 10.4 5.3-.7-3.1 1.7-6.2 4.9-6.2 1.4 0 2.8.6 3.7 1.6 1.1-.2 2.2-.6 3.2-1.2-.4 1.2-1.2 2.2-2.2 2.8 1-.1 2-.4 2.9-.8-.7 1-1.6 1.9-2.6 2.6z"></path>
</svg> </div>
<span> @caraboides</span>
</div>
</section>
</div>
</div>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true }
]
});
</script>
</body>
</html>