Cluster 2.0 – step 4 : Worker class and isolate internal messages#2388
Cluster 2.0 – step 4 : Worker class and isolate internal messages#2388AndreasMadsen wants to merge 45 commits intonodejs:masterfrom
Conversation
|
@visionmedia care to review? |
There was a problem hiding this comment.
this is a little too specific IMO, just exposing an array would be fine:
cluster.workers.forEach(...There was a problem hiding this comment.
workers are assigned to the cluster.worker by there uniqueID, this makes them very easy to find again. If we change this to an array people will get a lot of undefined values in there for loop. Also i don't like to have method like .push() that indicate someting there it very wrong.
There was a problem hiding this comment.
That would destroy the index
There was a problem hiding this comment.
Another option is to remove the eachWorker and then have a getWorkerById function, but I don't think that's a better solution.
There was a problem hiding this comment.
maybe:
cluster.workers = {};
var worker = new cluster.Worker;
cluster.workers[worker.id] = worker;then people just do:
for (var id in cluster.workers) {
whatever
}There was a problem hiding this comment.
This is how it works now, cluster.workers are public API (somehow I did not documenting it), the eachWorkers is just a wrapper around it. I say that we make the cluster.eachWorker internal only and make it as an example in the documentation, agree?
There was a problem hiding this comment.
im just thinking an array is not the right structure here
There was a problem hiding this comment.
?
cluster.workers has never been an array in this pull request: https://github.com/joyent/node/pull/2388/files#L1R80
There was a problem hiding this comment.
oh, well wtf haha yeah it's fine as-is then minus eachWorker
|
@ry I have done the IPC rewrite but how should userland isolate internal messages.
|
|
Also i have not merged the changes with this patch, because of the internal message filtering issue. |
|
Another option is to leak the messages out to the user.
This seems good. Are the callbacks removed? Next item for debate is |
|
@ry callbacks are removed on this patch, and process.send is supported in an experimental patch, i will merge it with this when i have modified process.on('message') and updated API doc. Thanks for the reply. |
|
Okay this is a little noisy, so i will just tell what has changed :) child_process: cluster: @ry ^ that is what you requested, so lets move to the next next debate item :) |
|
Ups the perfix is not |
|
This should fix it all, and testcases do parse :) EDIT: |
|
@ry please make a final review and land this patch on master. |
I know this is a big patch, but it is the foundation of the
cluster 2.0and cannot be split without creating a hopeless design.Documentation:
The documentation can be found here: doc
The important part here is that there now exist a Worker class/object this exist in both workers and clusters and are used in the same way. The worker object is a worker accessed using
cluster.workerand in the cluster the object is return fromforkand stored incluster.workersand a callback argument in a lot of functions and events.Example on worker object:
In the master you send a message to the worker using
worker.send. In a worker you send a message to the master usingworker.send.The next important part is the message system, this now isolate internal messages from userland, and support callbacks both ways.
This changes may seam to have nothing to do with each other, but the Worker object use internal messages more and the message system don't make sense without a standardized Worker object.
The API changes are:
cluster.forkdo no longer extend directly on onchild_process.fork. The object return bychild_process.forkmust now be accessed fromcluster.fork().process.worker.killis renamed toworker.destroy.worker.on('exit')is nowworker.on('death')process.sendbutcluster.worker.sendin the worker.process.on('message')butcluster.worker.on('message')in the worker.process.exitbutcluster.worker.destroy, the difference is thatdestroysend a suicide message to themaster, this indicate that we won't restart the worker (not implemented yet).CLUSTER_WORKER_IDis now calledCLUSTER_UNIQUE_ID, but this was not a part of the official API.worker.send()has change a lot internal, but should not cause any problems, the old function exist now asworker.process.send()The API additions are:
clusterobjectfork, online, listeningworkerobjectonline, listeningworker.statethis can benone, online, listening, deadworker.suicideifundefinedthe worker is alive, iffalsethe worker diedaccidently, iftruethe worker died by purpose.cluster.eachWorkeruse it to run a function on every living worker.worker.workerID.This is about the merging in the
cluster 2.0( see #2038 ) pull request