Search code examples
javascriptmemory-managementnode.jslinode

How can I profile my Node app to see where I'm using up memory and CPU resources?


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.


Solution

  • 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.