Привет, подскажите пожалуйста в чем разница между двумя кодами
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")
}
2 =>
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)
})
И почему выдается ошибка Error: bind EADDRINUSE при
=>
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")
}
Допустим 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);