LearnBoost / cluster

Node.JS multi-core server manager with plugins support.

Home Page:http://learnboost.github.com/cluster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cluster Worker load balancing imbalance

ynkm169 opened this issue · comments

I am just writing this separate issue here:

I used an simple test websocket example like the official doc. Nothing fancy.
One worker is working CPU to 100%. The other workers working like 5%..
Seems like the load balancing algorithm does not do round robin correctly....
When 1 CPU is loaded to 100% it causes problems maybe using a lot of memory which might break v8 1.7GB memory limit.

BTW, I am launching 100k connections with only two client simulation machine though (each machine launching about 50k test client connections) This means all 100k clients only have 2 unique IP. I am not sure how cluster module balances connections in relation to IP though.
According to the official doc and example:
http://nodejs.org/api/cluster.html

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

if (cluster.isMaster) {
    // Fork workers.
    for (var i = 0; i < numCPUs; i++) {
        cluster.fork();
    }

    cluster.on('exit', function(worker, code, signal) {
        console.log('worker ' + worker.process.pid + ' died');
    });
} else {
    // Workers can share any TCP connection
    // In this case its a HTTP server
    http.createServer(function(req, res) {
        res.writeHead(200);
        res.end("hello world\n");
    }).listen(8000);
}

When I actually remove all cluster code and instead launch say 6 node instances on 6 different ports and use HAproxy to do load balancing. All my workers are extreamly balanced, which is what I wanted...But I really don't want to use HAproxy if I could just use cluster module.