v1.0.1Published 2 years ago

Meteor CPU Profiler

This package makes it easy to record proper sampling CPU profiles of Meteor on the server. You can open the profile in Chrome for detailed analysis. A CPU profile looks like this in Chrome:

example flamechart

This package supports profiling the Meteor server process and send to S3 or save in the local disk.

if you want to profile Meteor build, use this package).


$ meteor add quave:profile

this package is only compatible with Meteor 1.8.2 or newer.


To profile the Meteor server at runtime, open the Meteor shell and run the following commands:

import Profiler from "meteor/quave:profile";

let profileName = 'myprofile';
let profilePath = '/path/to/profiles/myprofile.cpuprofile';
let profileMS = 10000;

Profiler.profileDuration(profileName, profilePath, profileMS);

This will profile your code for ten seconds and save the profile to /path/to/profiles/myprofile.cpuprofile.

You can call Profiler.profileDuration from anywhere in your code, but it is often convenient to call it from the Meteor shell.

If you don't have access to disk (like running on Galaxy) you can provide AWS S3 credentials in your settings and then the package is going to send to S3:

1    "quave:profile": {
2      "s3": {
3        "Bucket": "yourbucket",
4        "accessKeyId": "XXXXXXXXXXXXXXXXXXXX",
5        "secretAccessKey": "XXXXXXXX+Ox/xsajksadSJKDSAJKDJASKDJASKJDSA",
6        "region": "us-east-1"
7      }
8    }

You can start a profile calling a meteor Method from the console of your browser when your app is loaded there:

1Meteor.call('quave:profile#execute', { durationMs:3500 })

You can pass the durationMs to choose for how long do you want to profile.

If you are running on Galaxy you can use the URL for a specific container to profile a problematic container.

Reading Profiles

Chrome's javascript profiler is hidden by default. To enable it first open the DevTools main menu:

devtools main menu

After that, select More tools > JavaScript Profiler. The old profiler opens in a new panel called JavaScript Profiler. For more information reference this article.

Once the javascript profiler is enabled click Load to load your *.cpuprofile files. You can now navigate between your uploaded CPU profiles by using the sidebar on the left hand side.

For guidance on how to interpret these profiles, this tutorial is a good first step.