Hunting Performance Problems in Node.js Daniel Khan | @dkhan
Node.js is what the Company Outlaws use to finally introduce change
Node.js is what the Company Hipsters threw in just to break everything
Proactive Defense
Node.js is a C++ program controlled by V8 JavaScript
Hunting Memory Problems
process.memoryUsage() { rss: 4935680, heapTotal: 1826816, heapUsed: 650472 }
How to build a Memory Leak
theThing someMethod() longStr unused() originalThing Closure Context Reference Root
http://bit.ly/1PvijIy var snap = profiler.takeSnapshot(); snap.serialize(); v8-profiler
D e l t a
Hunting CPU Problems
calculateFibonacci();
http://bit.ly/1jQMbBR profiler.startProfiling(id); profiler.stopProfiling(id); v8-profiler
NODE_ENV=productionNODE_ENV=development Blog: http://bit.ly/1flz0Xm
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)
Finding the route
1980 20001995 2005 2010 2015 Stakeholders
“No man is an island” or … We need a holistic view.
Meet Application Performance Monitoring
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
@dkhan Daniel Khan daniel.khan@dynatrace.com Node.js Technology Lead

Hunting Performance Problems in Node.js and beyond

Editor's Notes

  • #11 But I really like this definition.
  • #12 What V8 does: It translates JavaScript into machine code and runs it.
  • #14 And every running program is represented by Work done on the CPU Data Stoed im memory And here we already have our two problem classes.
  • #16 Let’s review the memory handling of Node.js It’s very common and quite like Java. RSS: Code and Stack where local variables are stored It contains the heap for where objects and closures – let’s say long living resources like objects or closures are stored
  • #17 And it’s actually very easy to query the memory usage of a given Node process.
  • #18 And this is what you get if you create a graph of a running Node application. As we already see the heapUsed graph looks funny. It somehow is very dynamic and seems to follow a pattern. Something seems to take care that memory is freed. And I have a real live example of how this works.
  • #26 The console spits this out
  • #29 And now that we have found our problem we can add this. And the weekend is saved.
  • #33 My script will look at the memory usage and it constantly grows it will create a snapshot.
  • #37 Again v8 profiler. Again a function already there in V8. This will give you this.
  • #38 We can also look at some color coded chart that shows different function calls and the length. This pretty much resembles the flame charts we saw before. Some people like it – I don’t.
  • #39 What I did is: I fed the json tree to d3 sunburst.
  • #42 So this netflix latency problem.
  • #73 Speaking about Node.js let’s outline what this talk is about. When ever there’s bad press about Node.js it’s about performance problems. Here are two examples.