node js cpu 100%

We're having a problem where every once in a while one of our environments our node app runs on 100% CPU. The server isn't very active and usually runs on 0%-2% CPU.
I was wondering what are the common issues that might cause this problem and what would be the best way to find out what causing this issue.

technical spec:
node version 0.8.14
ubuntu 11.10
Intel(R) Xeon(R) CPU E5645 @ 2.40GHz

gems used:
"express" : 2.5.x, "log" : "1.2.x", "redis" : "0.8.x", "socket.io" : "0.9.x", "mongodb": ">= 0.9.6-7", "passport" : "0.x.x", "passport-local" : "0.x.x",

You can profile your app with node-tick.

  1. Install node-tick by sudo npm -g install tick
  2. Run your app with enabled profile node --prof ./app.js
  3. After some time with CPU 100% usage stop your app
  4. You can see v8.log in your app directory, now you can read it with node-tick-processor
  5. Run node-tick-processor and explain results

this is what i found:

    #!/usr/bin/env node

require(__dirname+"/processor-usage.js").startWatching();

var shouldRun = true;
var desiredLoadFactor = .5;

function blockCpuFor(ms) {
    var now = new Date().getTime();
    var result = 0
    while(shouldRun) {
        result += Math.random() * Math.random();
        if (new Date().getTime() > now +ms)
            return;
    }   
}

function start() {
    shouldRun = true;
    blockCpuFor(1000*desiredLoadFactor);
    setTimeout(start, 1000* (1 - desiredLoadFactor));
}

setInterval(function() {
    console.log("current process cpu usage: "+(global.processCpuUsage || 0)+"%");}
, 1000);

if (process.argv[2]) {
    var value = parseFloat(process.argv[2]);
    if (value < 0 || value > 1) {
        console.log("please give desired load value as a range [0..1]");
    process.exit(-1);
    } else {
        desiredLoadFactor = value;
    }
}
start();

on http://blackholethought.blogspot.de/2012/08/measuring-cpu-usage-of-nodejs-from.html

This feels like a repost to this question. You will need to write a script to record every request and then replay it. When you find the function that is causing the trouble you can troubleshoot it.