Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use profilers with Meteor?

My Meteor application, in server side (node process), is using much more CPU than would be acceptable, and I want to investigate it.

Two simultaneous clients are leading node to use 100% of CPU. It is probably related to a massive use of observers, but I need to investigate it further before changing the whole application.

So, what tool can I use to profile it? How to use it?

like image 231
zVictor Avatar asked Nov 15 '12 16:11

zVictor


4 Answers

The best solution I found is v8-profiler (plus node-inspector).

Install

  1. Go to [Meteor installation folder]/dev_bundle/lib/node_modules.

  2. exec $ npm install v8-profiler there.

  3. Add in your server code:

Meteor.startup(function() {
  profiler = __meteor_bootstrap__.require("v8-profiler")
  Meteor._debug("Server started!");
});
  • this method will be replaced soon

Use

  • Wherever in your app server code you can profile this way:

    profiler.startProfiling("name");                   //begin cpu profiling
    yourCode();
    var cpuProfile = profiler.stopProfiling("name");   //finish cpu profiling
    
  • Do not forget to run node-inspector

like image 120
zVictor Avatar answered Sep 21 '22 00:09

zVictor


APM, Application Performance Monitoring, is a Meteor package + cloud service developed by Arunoda Susiripala of MeteorHacks fame. It's in beta right now, and it looks very promising:

calls

From the Costly Calls tab, you can drill into methods and identify those that take longest:

screenshot

This 1-minute tutorial video shows just this identification of costly methods, which is probably what you want.

More screenshots

more screenshots

like image 35
Dan Dascalescu Avatar answered Sep 20 '22 00:09

Dan Dascalescu


You should also take a look at the Meteor-specific Observatory. It's a powerful server- and client-side logging package, with profiling support for arbitrary functions, and "automagical logging of template lifecycle methods, Collection methods (only find is supported so far), and Subscriptions profiling".

like image 43
Paul Young Avatar answered Sep 21 '22 00:09

Paul Young


NodeTime is a pretty awesome profiling service. It's free to use, which is especially helpful in situations like yours, and is super easy to set-up!

like image 45
Sdedelbrock Avatar answered Sep 21 '22 00:09

Sdedelbrock