Answer the question
In order to leave comments, you need to log in
How to implement clustering in nodejs?
Hello, please tell me what is the difference between the two codes
1 =>
if (cluster.isMaster) {
var count = 0
while(CPUs.length > count++) {
log.debug("Worker booted with ID: [" + cluster.fork().process.pid + "]")
}
cluster.on('exit', function (worker) {
log.error("Worker with ID: [" + worker.process.pid + "] died")
setTimeout(function () { cluster.fork() }, 1000)
})
} else {
// HERE
require("/server")
}
if (cluster.isMaster) {
var count = 0
while(CPUs.length > count++) {
log.debug("Worker booted with ID: [" + cluster.fork().process.pid + "]")
}
// HERE
require("/server")
cluster.on('exit', function (worker) {
log.error("Worker with ID: [" + worker.process.pid + "] died")
setTimeout(function () { cluster.fork() }, 1000)
})
if (cluster.isMaster) {
var count = 0
while(CPUs.length > count++) {
log.debug("Worker booted with ID: [" + cluster.fork().process.pid + "]")
}
//And
require("/server")
cluster.on('exit', function (worker) {
log.error("Worker with ID: [" + worker.process.pid + "] died")
setTimeout(function () { cluster.fork() }, 1000)
})
}else {
//And
require("/server")
}
var http = require("http")
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
// notify master about the request
process.send({ cmd: 'notifyRequest' });
}).listen(8000);
Answer the question
In order to leave comments, you need to log in
And why is the error Error: bind EADDRINUSE thrown
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question