node集群的问题:cluster.workers[id]的时候node会启动哪个端口,求大神帮看看
我遇到的问题是在用cluster.workers[id]的时候,node会动态启动端口,比如8000,但是有一些端口是不让起的,要不会报错,我想知道的是怎么在cluster.workers[id]的时候不让node启动某个指定的端口,部分代码如下:
var cluster = require(‘cluster’); var numCPUs = require(‘os’).cpus().length;
if (cluster.isMaster) { function afterMake(err, out) { if(out){ console.log(out); return; } // fsTool.remove(projectDir, function(){}); var jsDir = path.join(targetDir, ‘js/page’); var cssDir = path.join(targetDir, ‘css/page’);
gulp.src(cssDir + '/**/*.css')
.pipe(minicss())
.pipe(fileLog())
.pipe(gulp.dest(cssDir));
numCPUs = parseInt(numCPUs/2);
var count = numCPUs;
var jsFileList = [];
fsTool.walkSync(jsDir, function (file) {
jsFileList.push(file);
});
for (var i = 0; i < Math.min(parseInt(numCPUs), jsFileList.length); i++) {
cluster.fork();
}
Object.keys(cluster.workers).forEach(function (id) {
//重点看下面这段代码
** cluster.workers[id].send(jsFileList.shift());**