socket.io-mongo icon indicating copy to clipboard operation
socket.io-mongo copied to clipboard

100% CPU

Open techpines opened this issue 13 years ago • 21 comments

Hi, when I start this for some reason. I am seeing CPU spike to 100% when using with the cluster module:

MongoStore = require('socket.io-mongo')

cluster = require('cluster')
numCPUs = require('os').cpus().length;

// This is what the workers will do.
workers = function() {
    io = require('socket.io').listen(8080);

    io.configure(function() {
        io.set('store', new MongoStore())
    })
}

// Start forking if you are the master
if (cluster.isMaster) {
    for (var i = 0; i < numCPUs; i++) { cluster.fork() } 
} else { workers() }

node: 0.8.14 socket.io-mongo: 0.0.8 socket.io: 0.9.13

techpines avatar Dec 28 '12 16:12 techpines

I need to update to the latest mubsub version, it should be fixed there.

kof avatar Dec 28 '12 16:12 kof

@kof is there maybe an older npm version for "socket.io-mongo" where the code is working?

techpines avatar Dec 28 '12 18:12 techpines

I think this bug was the whole time there, but it was not always reproducible.

kof avatar Dec 28 '12 18:12 kof

If you wait some days I will migrate to the new version of mubsub. Do you want to use it in production?

kof avatar Dec 28 '12 18:12 kof

Yea, I wanted to use it in production.

techpines avatar Dec 28 '12 19:12 techpines

@kof awesome - also wonder if you're looking into the issue with {safe: true} that keeps popping up? I couldn't see a way to pass in that option

tanepiper avatar Jan 15 '13 10:01 tanepiper

I think you can pass proper options already.

kof avatar Jan 15 '13 11:01 kof

I'm seeing this same issue -- 100% CPU usage with cluster. I'm using node.js 0.8.12 and the latest versions of all modules.

zaneclaes avatar Mar 17 '13 20:03 zaneclaes

heh ... need to find time to finally complete this one #3

kof avatar Mar 17 '13 20:03 kof

Ack, I wish I had read through the issues before moving this from my staging server (which doesn't use cluster) to production (which does). #kaboom there goes my whole server array :(

zaneclaes avatar Mar 17 '13 20:03 zaneclaes

actually this issue should exist also without cluster

kof avatar Mar 17 '13 20:03 kof

Is there any way I can easily work around this? I'm in a tight spot -- I just pushed a whole bunch of code to production, and my servers are now down. I hate to do a rollback, but it may be the only option...

zaneclaes avatar Mar 17 '13 20:03 zaneclaes

try to merge this pull .... #3 also good to know if it works ... haven't checked yet ... tests are not running but probably it works for you ...

kof avatar Mar 17 '13 20:03 kof

Please excuse my ignorance -- is there a way to install the pull with NPM?

zaneclaes avatar Mar 17 '13 20:03 zaneclaes

yes, you can fork it and reference it directly to your fork in your package.json

example:

    "connect-mongodb"   : "https://github.com/my-account/connect-mongodb/tarball/master",

kof avatar Mar 17 '13 20:03 kof

Well... as best as I can tell, the CPU is fixed, but the module no longer works. I'm getting "client not handshaken" errors from socket.io (eg, the connections are not shared).

zaneclaes avatar Mar 17 '13 22:03 zaneclaes

There are a bunch of console.log statements being spit out, too, like the following:

{ name: 'open', nodeId: 424686859572, args: '["GopX4DCM9mgy3h93h25-"]', _id: 5146480b16dcde722f000025 } { name: 'open', nodeId: 424686859572, args: '["GopX4DCM9mgy3h93h25-"]', _id: 5146480b16dcde722f000028 }

zaneclaes avatar Mar 17 '13 22:03 zaneclaes

Ok, then I need to make all tests running again and find out whats not ported or wrongly ported in this pull ... so sorry, no quick solution right now.

kof avatar Mar 17 '13 22:03 kof

Ok, thanks -- let me know if I can help at all. I've fallen back on long-polling on my prod servers for now, but it's a bit of a patch solution which I'd like to correct. So, any testing you need, just LMK ;)

zaneclaes avatar Mar 17 '13 22:03 zaneclaes

Hey kof... any chance you have some time to take a look at this? It would be much appreciated.

zaneclaes avatar Mar 26 '13 18:03 zaneclaes

I will try to find it ...

kof avatar Mar 26 '13 18:03 kof