75
Hunting Performance Problems in Node.js CodeMotion Amsterdam 2016 Daniel Khan | @dkhan

Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Embed Size (px)

Citation preview

Page 1: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Hunting Performance Problems in Node.jsCodeMotion Amsterdam 2016

Daniel Khan | @dkhan

Page 2: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 3: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 4: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 5: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 6: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 7: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Node.js is what the Company Outlaws

use to finally introduce change

Page 8: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 9: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 10: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 11: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Node.js is what the Company Hipsters threw in

just to break everything

Page 12: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 13: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Proactive Defense

Page 14: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Node.js is a C++ program controlled by V8 JavaScript

Page 15: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 16: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 17: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 18: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Hunting Memory Problems

Page 19: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 20: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

process.memoryUsage(){ rss: 4935680, heapTotal: 1826816, heapUsed: 650472 }

Page 21: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 22: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 23: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 24: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 25: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 26: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 27: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 28: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 29: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 30: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 31: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

How to build a Memory Leak

Page 32: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 33: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

theThing

someMethod()

longStr

unused()

originalThing

Closure Context

Reference

Root

Page 34: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 35: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

http://bit.ly/1PvijIy

var snap = profiler.takeSnapshot();snap.serialize();

v8-profiler

Page 36: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Delta

Page 37: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Hunting CPU Problems

Page 38: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

calculateFibonacci();

Page 39: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

http://bit.ly/1jQMbBR

profiler.startProfiling(id); profiler.stopProfiling(id);

v8-profiler

Page 40: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 41: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 42: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 43: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

NODE_ENV=productionNODE_ENV=development

Blog: http://bit.ly/1flz0Xm

Page 44: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 45: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

get(‘/routeA’, function(){})

get(‘/routeB’, function(){})

get(‘/routeC’, function(){})

get(‘/routeD’, function(){})

get(‘/routeE’, function(){})

get(‘/routeA’, function(){})

get(‘/routeX’, function(){})

get(‘/^(route|router)\/(.+)’, function(){})

HTTP GET /routeX

get(‘/routeA’, function(){})

get(‘/routeX’, function(){})

O(n)

Page 46: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Finding the route

Page 47: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 48: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 49: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 50: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 51: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 52: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 53: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 54: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 55: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 56: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 57: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

1980 20001995 2005 2010 2015

Stakeholders

Page 58: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 59: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 60: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Browser Webserver Node Java Oracle

Page 61: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

“No man is an island”or … We need a holistic view.

Page 62: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Meet Application Performance Monitoring

Page 63: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 64: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 65: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 66: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 67: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 68: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 69: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 70: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 71: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 72: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 73: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

Takeaways• Node.js introduces change• Use dedicated tools like N|Solid to monitor Node.js specific metrics like CPU and Memory

Usage• Protect your boundaries by actively monitoring incoming and outgoing transactions• Use APM Solutions like Dynatrace or Ruxit to get a holistic view for all transactions passing

through all tiers of your stack

Page 74: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Page 75: Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016

@dkhan

Daniel [email protected]

Node.js Technology Lead