Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process.send / master.on("message" not work #51

Open
tablecell opened this issue Oct 29, 2016 · 0 comments
Open

process.send / master.on("message" not work #51

tablecell opened this issue Oct 29, 2016 · 0 comments

Comments

@tablecell
Copy link

tablecell commented Oct 29, 2016

test code

var cluster = require('cluster');  
var sticky = require('sticky-session');
const PORT=5000;

var totalReqs = 0;
var localReq = 0;

var server = require('http').createServer(function(req, res) {
    res.end(process.pid+ ' worker: ' + cluster.worker.id);
    process.send(" worker  " + process.pid + "  local is " + localReq + "  sum is " + totalReqs);
});

if (!sticky.listen(server, PORT)) {
    // Master code
    if (cluster.isMaster) {
        Object.keys(cluster.workers).forEach(function(i){
            cluster.workers[i].on('message', function(msg) {
                totalReqs++;
                console.log(totalReqs);
            });
        });
    }
    server.once('listening', function() {
        console.log('server started on  port',PORT);
    });
} else {
    // Worker code
    console.log(process.pid);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant