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?
The best solution I found is v8-profiler (plus node-inspector).
Go to [Meteor installation folder]/dev_bundle/lib/node_modules
.
exec $ npm install v8-profiler
there.
Add in your server code:
Meteor.startup(function() {
profiler = __meteor_bootstrap__.require("v8-profiler")
Meteor._debug("Server started!");
});
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
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:
From the Costly Calls tab, you can drill into methods and identify those that take longest:
This 1-minute tutorial video shows just this identification of costly methods, which is probably what you want.
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".
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With