javascript - node-ipc cluster only using 1 worker -
i using node-ipc alongside cluster in nodejs on windows 8.1, , have clustered ipc server , created many processes have cpu's (4 in case), of them sharing same port , id.
i connecting multiple clients clustered server , expecting master process delegate task worker free. not work , master chooses same worker.
i have checked , worker processes running. how can master chooses least busy worker every time?
below server code
var os = require('os'); var numcpus = os.cpus().length; var cluster = require('cluster'); var ipc = require('node-ipc'); if (cluster.ismaster) { console.log("i master, launching workers"); (var = 0; < numcpus; i++) { cluster.fork(); console.log("worker " + + " launched"); } } else { ipc.config.id = 'worldserver'; ipc.config.retry= 1500; ipc.config.silent = true; console.log(`i worker #${cluster.worker.id}`, process.pid); ipc.serve( function(){ ipc.server.on('sayhello', function(data,socket) { console.log(`i worker #${cluster.worker.id}`, process.pid); ipc.server.emit( socket, 'message', 'hello' ); } ); ipc.server.on('error', function(e) { console.log('ipc error!!', e); }); }); ipc.server.start(); }
here client code
var ipc=require('node-ipc'); ipc.config.id = 'hello'; ipc.config.retry= 1500; ipc.config.silent = true; setinterval(function() { ipc.connectto( 'worldserver', function(){ console.log("sending something"); ipc.of.worldserver.emit( 'sayhello', "true" ); ipc.of.worldserver.on( 'message', function(data){ console.log('i got message server:'); console.log(data); } ); } ); }, 20);
Comments
Post a Comment