Open Arech opened 13 years ago
you can use the existing internal api for this, but I dont want cluster to become an IPC library, it has nothing to do with that really aside from the fact that it needs it internally. I would recommend just using other libraries for the IPC, if nothing great exists I can tear out what I use internally and make a little local socket IPC lib or something
Motivation behind the proposition consists of the following:
//master process:
//handle worker creation
proc.on('worker', function(w){
console.log("Worker #%d created",w.id);
notifyMgmtServer(true,w);
});
//handle arrived data
proc.on('worker data', function(w,data){
if (!data || !data.action) {
log.error('WTF?! invalid package received in workerdata');
return;
}
//process package
...
};
//handle worker suicide
proc.on('worker killed', function(w){
log.info("Worker #"+w.id+" has been killed.");
notifyMgmtServer(false,w);
});
Its just a logic and a common sence.
This is your library and you are the one who decides whether to evolve it or leave it as is. But if you decide not to add this feature, could you please export Worker
variable from master.js
exports? This won't hurt and won't offend somebody's sense of beauty, but someone may want to add more features to it's prototype...
Thanks.
the argument certainly goes both ways, but im just saying that cluster is not an IPC library
Hi again)
Sometimes it is necessary to put management code into master process and collect some data from workers. This feature requires IPC link between master and worker processes. Cluster already uses such IPC link and it can be easily extended to provide necessary API for the request. Here is a quick&dirty proposition:
Update
worker.js
Worker.prototype.start
For
master.js
Master.prototype.start
function aftervar worker = new Worker(this);
:Now one can easily do things like this: