javascript – 如何在Windows上运行Node Cluster?

前端之家收集整理的这篇文章主要介绍了javascript – 如何在Windows上运行Node Cluster?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都知道如何在 windows上运行Node Cluster?我无法在网路上找到任何文章,似乎无法解决这个问题:
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: write ENOTSUP
    at exports._errnoException (util.js:1007:11)
    at ChildProcess.target._send (internal/child_process.js:634:20)
    at ChildProcess.target.send (internal/child_process.js:521:19)
    at sendHelper (cluster.js:751:15)
    at send (cluster.js:534:12)
    at cluster.js:509:7
    at SharedHandle.add (cluster.js:99:3)
    at queryServer (cluster.js:501:12)
    at Worker.onmessage (cluster.js:449:7)
    at ChildProcess.<anonymous> (cluster.js:765:8)

代码

if (cluster.isMaster) {
    for (let i = 0; i < numcpus; i++) {
        cluster.fork();
    }
    cluster.on('online',(worker) => {
        console.log('Worker ' + worker.process.pid + ' is online');
    });
    cluster.on('exit',(worker,code,signal) => {
        console.log(`Worker ${worker.process.pid} died with code ${code} and signal ${signal}`);
    });
} else {
    console.log('else part ');
    openPort();
}

function openPort() {
    let server = dgram.createSocket('udp4');
    server.bind(port,host);
    server.on('message',processMessage);
}

解决方法

在v0.11.14(对于Linux和OSX)中添加了对UDP群集的支持.
在node.js主机上检查 file,其中说“Windows目前不支持dgram聚类”

猜你在找的JavaScript相关文章