@@ -6,8 +6,8 @@ A single instance of Node.js runs in a single thread. To take advantage of
66multi-core systems the user will sometimes want to launch a cluster of Node.js
77processes to handle the load.
88
9- The cluster module allows you to easily create child processes that
10- all share server ports.
9+ The cluster module allows easy creation of child processes that all share
10+ server ports.
1111
1212``` js
1313const cluster = require (' cluster' );
@@ -88,27 +88,24 @@ Node.js process and a cluster worker differs:
8888 idea of what the number 7 file descriptor references.
89892 . ` server.listen(handle) ` Listening on handles explicitly will cause
9090 the worker to use the supplied handle, rather than talk to the master
91- process. If the worker already has the handle, then it's presumed
92- that you know what you are doing.
91+ process.
93923 . ` server.listen(0) ` Normally, this will cause servers to listen on a
9493 random port. However, in a cluster, each worker will receive the
9594 same "random" port each time they do ` listen(0) ` . In essence, the
96- port is random the first time, but predictable thereafter. If you
97- want to listen on a unique port, generate a port number based on the
98- cluster worker ID.
95+ port is random the first time, but predictable thereafter. To listen
96+ on a unique port, generate a port number based on the cluster worker ID.
9997
100- There is no routing logic in Node.js, or in your program, and no shared
101- state between the workers. Therefore, it is important to design your
102- program such that it does not rely too heavily on in-memory data objects
103- for things like sessions and login.
98+ * Note* : Node.js does not provide routing logic. It is, therefore important to
99+ design an application such that it does not rely too heavily on in-memory data
100+ objects for things like sessions and login.
104101
105102Because workers are all separate processes, they can be killed or
106- re-spawned depending on your program's needs, without affecting other
103+ re-spawned depending on a program's needs, without affecting other
107104workers. As long as there are some workers still alive, the server will
108105continue to accept connections. If no workers are alive, existing connections
109- will be dropped and new connections will be refused. Node.js does not
110- automatically manage the number of workers for you , however. It is your
111- responsibility to manage the worker pool for your application's needs.
106+ will be dropped and new connections will be refused. Node.js does not
107+ automatically manage the number of workers, however. It is the application's
108+ responsibility to manage the worker pool based on its own needs.
112109
113110
114111
@@ -141,7 +138,7 @@ added: v0.7.3
141138
142139This event is the same as the one provided by [ ` child_process.fork() ` ] [ ] .
143140
144- In a worker you can also use ` process.on('error') ` .
141+ Within a worker, ` process.on('error') ` may also be used .
145142
146143### Event: 'exit'
147144<!-- YAML
@@ -192,8 +189,9 @@ added: v0.7.0
192189* ` message ` {Object}
193190* ` handle ` {undefined|Object}
194191
195- Similar to the ` cluster.on('message') ` event, but specific to this worker. In a
196- worker you can also use ` process.on('message') ` .
192+ Similar to the ` cluster.on('message') ` event, but specific to this worker.
193+
194+ Within a worker, ` process.on('message) ` may also be used.
197195
198196See [ ` process ` event: ` 'message' ` ] [ ] .
199197
@@ -336,9 +334,9 @@ added: v6.0.0
336334
337335Set by calling ` .kill() ` or ` .disconnect() ` . Until then, it is ` undefined ` .
338336
339- The boolean ` worker.exitedAfterDisconnect ` lets you distinguish between voluntary
340- and accidental exit, the master may choose not to respawn a worker based on
341- this value.
337+ The boolean ` worker.exitedAfterDisconnect ` allows distinguishing between
338+ voluntary and accidental exit, the master may choose not to respawn a worker
339+ based on this value.
342340
343341``` js
344342cluster .on (' exit' , (worker , code , signal ) => {
@@ -369,9 +367,9 @@ cluster.workers
369367added: v0.11.14
370368-->
371369
372- This function returns ` true ` if the worker is connected to its master via its IPC
373- channel, ` false ` otherwise. A worker is connected to its master after it's been
374- created. It is disconnected after the ` 'disconnect' ` event is emitted.
370+ This function returns ` true ` if the worker is connected to its master via its
371+ IPC channel, ` false ` otherwise. A worker is connected to its master after it
372+ has been created. It is disconnected after the ` 'disconnect' ` event is emitted.
375373
376374### worker.isDead()
377375<!-- YAML
@@ -469,7 +467,7 @@ An alias to [`worker.exitedAfterDisconnect`][].
469467
470468Set by calling ` .kill() ` or ` .disconnect() ` . Until then, it is ` undefined ` .
471469
472- The boolean ` worker.suicide ` lets you distinguish between voluntary
470+ The boolean ` worker.suicide ` is used to distinguish between voluntary
473471and accidental exit, the master may choose not to respawn a worker based on
474472this value.
475473
@@ -540,7 +538,7 @@ added: v0.7.0
540538* ` worker ` {cluster.Worker}
541539
542540When a new worker is forked the cluster module will emit a ` 'fork' ` event.
543- This can be used to log worker activity, and create your own timeout.
541+ This can be used to log worker activity, and create a custom timeout.
544542
545543``` js
546544const timeouts = [];
@@ -568,13 +566,14 @@ added: v0.7.0
568566* ` worker ` {cluster.Worker}
569567* ` address ` {Object}
570568
571- After calling ` listen() ` from a worker, when the ` 'listening' ` event is emitted on
572- the server, a ` 'listening' ` event will also be emitted on ` cluster ` in the master.
569+ After calling ` listen() ` from a worker, when the ` 'listening' ` event is emitted
570+ on the server a ` 'listening' ` event will also be emitted on ` cluster ` in the
571+ master.
573572
574- The event handler is executed with two arguments, the ` worker ` contains the worker
575- object and the ` address ` object contains the following connection properties:
576- ` address ` , ` port ` and ` addressType ` . This is very useful if the worker is listening
577- on more than one address.
573+ The event handler is executed with two arguments, the ` worker ` contains the
574+ worker object and the ` address ` object contains the following connection
575+ properties: ` address ` , ` port ` and ` addressType ` . This is very useful if the
576+ worker is listening on more than one address.
578577
579578``` js
580579cluster .on (' listening' , (worker , address ) => {
@@ -610,8 +609,9 @@ See [child_process event: 'message'][].
610609Before Node.js v6.0, this event emitted only the message and the handle,
611610but not the worker object, contrary to what the documentation stated.
612611
613- If you need to support older versions and don't need the worker object,
614- you can work around the discrepancy by checking the number of arguments:
612+ If support for older versions is required but a worker object is not
613+ required, it is possible to work around the discrepancy by checking the
614+ number of arguments:
615615
616616``` js
617617cluster .on (' message' , (worker , message , handle ) => {
@@ -713,8 +713,8 @@ added: v0.11.2
713713
714714The scheduling policy, either ` cluster.SCHED_RR ` for round-robin or
715715` cluster.SCHED_NONE ` to leave it to the operating system. This is a
716- global setting and effectively frozen once you spawn the first worker
717- or call ` cluster.setupMaster() ` , whatever comes first.
716+ global setting and effectively frozen once either the first worker is spawned,
717+ or ` cluster.setupMaster() ` is called, whichever comes first.
718718
719719` SCHED_RR ` is the default on all operating systems except Windows.
720720Windows will change to ` SCHED_RR ` once libuv is able to effectively
@@ -750,7 +750,7 @@ changes:
750750After calling ` .setupMaster() ` (or ` .fork() ` ) this settings object will contain
751751the settings, including the default values.
752752
753- This object is not supposed to be changed or set manually, by you .
753+ This object is not intended to be changed or set manually.
754754
755755## cluster.setupMaster([ settings] )
756756<!-- YAML
@@ -850,8 +850,7 @@ eachWorker((worker) => {
850850});
851851```
852852
853- Should you wish to reference a worker over a communication channel, using
854- the worker's unique id is the easiest way to find the worker.
853+ Using the worker's unique id is the easiest way to locate the worker.
855854
856855``` js
857856socket .on (' data' , (id ) => {
0 commit comments