You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
The rewrite of cluster in 0.7 is basically done (or at least from my side). I have got a lot of emails over the time, many of them are about high level API that could be supported by 10 lines of userland code. But between them I think there are two valid subjects:
cluster.destroy([callback])
This is much like the cluster.disconnect([callback]) method, it destroy all workers (don't disconnect) and then close all server handlers. It could be implemented in userland with:
cluster.destroy=function(callback){varmap=Object.keys(cluster.workers);varmissing=map.length;varclosemap.forEach(function(uniqueID){varworker=cluster.workers[uniqueID];worker.on('death',function(){missing-=1;// since no more workers exist cluster.disconnect // won't disconnect any and immediately close all handlersif(missing===0)cluster.disconnect(callback);}worker.destroy();});};
So as you see it is quite easy to implement, however it isn't very obiouse. It do also give some API consistency: there is a worker.disconnect and a cluster.disconnect method, however there is only a worker.destroy method.
Worker = worker.restart() or worker.workerID
At some point a workerID was renamed to uniqueID because workerID was going to mean something else when using cluster.autoFork() (not implemented and will properly never be implemented). It was suposed to be an ID there started at 0
and increased to os.cpus().length (just like the LeanBoost cluster module).
However since this was never implemented uniqueID should be renamed back to workerID or a worker.restart() method should be implemented. When calling the worker.restart() method (assuming the worker is dead) the workerID will then be reused and uniqueID will increases.
This could also be implemented in userland, but is a little more complicated (so I won't write an example) because the env option in cluster.fork([env]) should be stored somewhere and then reused. When userland wan't to restart the worker.
With a worker.restart() method the unimplemented cluster.autoFork() cloud be implemented in userland this way:
The rewrite of cluster in 0.7 is basically done (or at least from my side). I have got a lot of emails over the time, many of them are about high level API that could be supported by 10 lines of userland code. But between them I think there are two valid subjects:
cluster.destroy([callback])
This is much like the
cluster.disconnect([callback])
method, it destroy all workers (don't disconnect) and then close all server handlers. It could be implemented in userland with:So as you see it is quite easy to implement, however it isn't very obiouse. It do also give some API consistency: there is a
worker.disconnect
and acluster.disconnect
method, however there is only aworker.destroy
method.Worker = worker.restart() or worker.workerID
At some point a
workerID
was renamed touniqueID
becauseworkerID
was going to mean something else when usingcluster.autoFork()
(not implemented and will properly never be implemented). It was suposed to be an ID there started at 0and increased to
os.cpus().length
(just like the LeanBoost cluster module).However since this was never implemented
uniqueID
should be renamed back toworkerID
or aworker.restart()
method should be implemented. When calling theworker.restart()
method (assuming the worker is dead) theworkerID
will then be reused anduniqueID
will increases.This could also be implemented in userland, but is a little more complicated (so I won't write an example) because the
env
option incluster.fork([env])
should be stored somewhere and then reused. When userland wan't to restart the worker.With a
worker.restart()
method the unimplementedcluster.autoFork()
cloud be implemented in userland this way:Note that I don't think userland should extend the cluster module object, but I think it made the examples more easy to understand.
The text was updated successfully, but these errors were encountered: