8

My website, CompassionPit.com, is powered by Node.js. I have released the source code; it's hosted at GitHub. The app itself is running on a Linode with 768MB of RAM (I recently upgraded the server; it was at 512MB).

Recently I have been getting CPU usage notifications from Linode: we're increasingly often at 90%+ usage. I called Linode to see what I could do about upgrading my access to CPU resources, but apparently I'm okay for now, since if we max out to 100% then we can spill over into the next 3 cores (Linodes are 4 processor Xen instances).

How can I profile my Node app to see where I'm using up memory and CPU resources? I predict I'll soon need to restructure the application to be run by a multiple server setup, but I intuitively believe that proper profiling will lead to smarter architecture decisions. Please correct me if I'm wrong.

Zack Burt
  • 8,257
  • 10
  • 53
  • 81

3 Answers3

3

Node inspector can't profile node after version 0.6.x

The following plugin has been updated to work with new version of v8 (node 0.7.x +). It's the only one besides nodetime.com that is still working. It uses the actual webkit debugger:

https://github.com/c4milo/node-webkit-agent

It has very clear instructions as well.

Scott
  • 1,012
  • 7
  • 14
  • This is not true anymore. Node inspector has been updated in the meantime. – chicken Mar 05 '14 at 11:59
  • @LeoKoppelkamm Where are you seeing that Node Inspector supports profiling? The [README still states](https://github.com/node-inspector/node-inspector#known-issues) "Profiler is not implemented yet". – John Mar 25 '14 at 18:23
  • I was refering to the 0.6.x comment. Node inspector was completely broken for a while, but that has been fixed in the mean time. I'm gonna edit the answer to clear that up. – chicken Mar 26 '14 at 20:17
1

As of v6.3.0, you can now run node --inspect your_script.js.

Node will print a URL to the console, which can be opened in Chrome, which will connect you to reveal a fully-functional Web Inspector that you can use to profile the Node process.

Run node --inspect --debug-brk to immediately pause execution (which is handy if you need to start a profiling session as soon as your application starts)

schmod
  • 777
  • 9
  • 19
1

I've had reasonable success using https://github.com/dannycoates/node-inspector for profiling. There's a setup guide at the bottom of the README file.

As of later versions of Node.js, the profiling part of node-inspector no longer functions. I've had reasonable success with --prof (http://code.google.com/p/v8/wiki/V8Profiler) and https://github.com/c4milo/node-webkit-agent as mentioned in the answer below.

Glenjamin
  • 7,150
  • 6
  • 25
  • 26
  • I would like to chime in that from the #Node.js channel on Freenode, people have also suggested dtrace (credit: H4ns) and v8-profiler (Glenjamin). – Zack Burt Sep 05 '11 at 08:47