@@ -18,8 +18,8 @@ const cluster = require('cluster');
1818const http = require (' http' );
1919const numCPUs = require (' os' ).cpus ().length ;
2020
21- if (cluster .isParent ) {
22- console .log (` Parent ${ process .pid } is running` );
21+ if (cluster .isPrimary ) {
22+ console .log (` Primary ${ process .pid } is running` );
2323
2424 // Fork workers.
2525 for (let i = 0 ; i < numCPUs; i++ ) {
@@ -45,7 +45,7 @@ Running Node.js will now share port 8000 between the workers:
4545
4646``` console
4747$ node server.js
48- Parent 3596 is running
48+ Primary 3596 is running
4949Worker 4324 started
5050Worker 4520 started
5151Worker 6056 started
@@ -66,12 +66,12 @@ The cluster module supports two methods of distributing incoming
6666connections.
6767
6868The first one (and the default one on all platforms except Windows),
69- is the round-robin approach, where the parent process listens on a
69+ is the round-robin approach, where the primary process listens on a
7070port, accepts new connections and distributes them across the workers
7171in a round-robin fashion, with some built-in smarts to avoid
7272overloading a worker process.
7373
74- The second approach is where the parent process creates the listen
74+ The second approach is where the primary process creates the listen
7575socket and sends it to interested workers. The workers then accept
7676incoming connections directly.
7777
@@ -81,16 +81,16 @@ to operating system scheduler vagaries. Loads have been observed
8181where over 70% of all connections ended up in just two processes,
8282out of a total of eight.
8383
84- Because ` server.listen() ` hands off most of the work to the parent
84+ Because ` server.listen() ` hands off most of the work to the primary
8585process, there are three cases where the behavior between a normal
8686Node.js process and a cluster worker differs:
8787
88- 1 . ` server.listen({fd: 7}) ` Because the message is passed to the parent ,
88+ 1 . ` server.listen({fd: 7}) ` Because the message is passed to the primary ,
8989 file descriptor 7 ** in the parent** will be listened on, and the
9090 handle passed to the worker, rather than listening to the worker's
9191 idea of what the number 7 file descriptor references.
92922 . ` server.listen(handle) ` Listening on handles explicitly will cause
93- the worker to use the supplied handle, rather than talk to the parent
93+ the worker to use the supplied handle, rather than talk to the primary
9494 process.
95953 . ` server.listen(0) ` Normally, this will cause servers to listen on a
9696 random port. However, in a cluster, each worker will receive the
@@ -121,7 +121,7 @@ added: v0.7.0
121121* Extends: {EventEmitter}
122122
123123A ` Worker ` object contains all public information and method about a worker.
124- In the parent it can be obtained using ` cluster.workers ` . In a worker
124+ In the primary it can be obtained using ` cluster.workers ` . In a worker
125125it can be obtained using ` cluster.worker ` .
126126
127127### Event: ` 'disconnect' `
@@ -201,14 +201,14 @@ Within a worker, `process.on('message')` may also be used.
201201
202202See [ ` process ` event: ` 'message' ` ] [ ] .
203203
204- Here is an example using the message system. It keeps a count in the parent
204+ Here is an example using the message system. It keeps a count in the primary
205205process of the number of HTTP requests received by the workers:
206206
207207``` js
208208const cluster = require (' cluster' );
209209const http = require (' http' );
210210
211- if (cluster .isParent ) {
211+ if (cluster .isPrimary ) {
212212
213213 // Keep track of http requests
214214 let numReqs = 0 ;
@@ -240,7 +240,7 @@ if (cluster.isParent) {
240240 res .writeHead (200 );
241241 res .end (' hello world\n ' );
242242
243- // Notify parent about the request
243+ // Notify primary about the request
244244 process .send ({ cmd: ' notifyRequest' });
245245 }).listen (8000 );
246246}
@@ -275,7 +275,7 @@ changes:
275275In a worker, this function will close all servers, wait for the ` 'close' ` event
276276on those servers, and then disconnect the IPC channel.
277277
278- In the parent , an internal message is sent to the worker causing it to call
278+ In the primary , an internal message is sent to the worker causing it to call
279279` .disconnect() ` on itself.
280280
281281Causes ` .exitedAfterDisconnect ` to be set.
@@ -299,7 +299,7 @@ close them. It also may be useful to implement a timeout, killing a worker if
299299the ` 'disconnect' ` event has not been emitted after some time.
300300
301301``` js
302- if (cluster .isParent ) {
302+ if (cluster .isPrimary ) {
303303 const worker = cluster .fork ();
304304 let timeout;
305305
@@ -343,7 +343,7 @@ This property is `true` if the worker exited due to `.kill()` or
343343worker has not exited, it is ` undefined ` .
344344
345345The boolean [ ` worker.exitedAfterDisconnect ` ] [ ] allows distinguishing between
346- voluntary and accidental exit, the parent may choose not to respawn a worker
346+ voluntary and accidental exit, the primary may choose not to respawn a worker
347347based on this value.
348348
349349``` js
@@ -375,8 +375,8 @@ While a worker is alive, this is the key that indexes it in
375375added: v0.11.14
376376-->
377377
378- This function returns ` true ` if the worker is connected to its parent via its
379- IPC channel, ` false ` otherwise. A worker is connected to its parent after it
378+ This function returns ` true ` if the worker is connected to its primary via its
379+ IPC channel, ` false ` otherwise. A worker is connected to its primary after it
380380has been created. It is disconnected after the ` 'disconnect' ` event is emitted.
381381
382382### ` worker.isDead() `
@@ -392,8 +392,8 @@ const cluster = require('cluster');
392392const http = require (' http' );
393393const numCPUs = require (' os' ).cpus ().length ;
394394
395- if (cluster .isParent ) {
396- console .log (` Parent ${ process .pid } is running` );
395+ if (cluster .isPrimary ) {
396+ console .log (` Primary ${ process .pid } is running` );
397397
398398 // Fork workers.
399399 for (let i = 0 ; i < numCPUs; i++ ) {
@@ -425,9 +425,10 @@ added: v0.9.12
425425* ` signal ` {string} Name of the kill signal to send to the worker
426426 process. ** Default** : ` 'SIGTERM' `
427427
428- This function will kill the worker. In the parent, it does this by disconnecting
429- the ` worker.process ` , and once disconnected, killing with ` signal ` . In the
430- worker, it does it by disconnecting the channel, and then exiting with code ` 0 ` .
428+ This function will kill the worker. In the primary, it does this
429+ by disconnecting the ` worker.process ` , and once disconnected, killing
430+ with ` signal ` . In the worker, it does it by disconnecting the channel,
431+ and then exiting with code ` 0 ` .
431432
432433Because ` kill() ` attempts to gracefully disconnect the worker process, it is
433434susceptible to waiting indefinitely for the disconnect to complete. For example,
@@ -478,18 +479,18 @@ changes:
478479* ` callback ` {Function}
479480* Returns: {boolean}
480481
481- Send a message to a worker or parent , optionally with a handle.
482+ Send a message to a worker or primary , optionally with a handle.
482483
483- In the parent this sends a message to a specific worker. It is identical to
484+ In the primary this sends a message to a specific worker. It is identical to
484485[ ` ChildProcess.send() ` ] [ ] .
485486
486- In a worker this sends a message to the parent . It is identical to
487+ In a worker this sends a message to the primary . It is identical to
487488` process.send() ` .
488489
489- This example will echo back all messages from the parent :
490+ This example will echo back all messages from the primary :
490491
491492``` js
492- if (cluster .isParent ) {
493+ if (cluster .isPrimary ) {
493494 const worker = cluster .fork ();
494495 worker .send (' hi there' );
495496
@@ -583,7 +584,7 @@ added: v0.7.0
583584
584585After calling ` listen() ` from a worker, when the ` 'listening' ` event is emitted
585586on the server a ` 'listening' ` event will also be emitted on ` cluster ` in the
586- parent .
587+ primary .
587588
588589The event handler is executed with two arguments, the ` worker ` contains the
589590worker object and the ` address ` object contains the following connection
@@ -617,7 +618,7 @@ changes:
617618* ` message ` {Object}
618619* ` handle ` {undefined|Object}
619620
620- Emitted when the cluster parent receives a message from any worker.
621+ Emitted when the cluster primary receives a message from any worker.
621622
622623See [ ` child_process ` event: ` 'message' ` ] [ ] .
623624
@@ -629,9 +630,9 @@ added: v0.7.0
629630* ` worker ` {cluster.Worker}
630631
631632After forking a new worker, the worker should respond with an online message.
632- When the parent receives an online message it will emit this event.
633+ When the primary receives an online message it will emit this event.
633634The difference between ` 'fork' ` and ` 'online' ` is that fork is emitted when the
634- parent forks a worker, and ` 'online' ` is emitted when the worker is running.
635+ primary forks a worker, and ` 'online' ` is emitted when the worker is running.
635636
636637``` js
637638cluster .on (' online' , (worker ) => {
@@ -646,11 +647,11 @@ added: v0.7.1
646647
647648* ` settings ` {Object}
648649
649- Emitted every time [ ` .setupParent () ` ] [ ] is called.
650+ Emitted every time [ ` .setupPrimary () ` ] [ ] is called.
650651
651652The ` settings ` object is the ` cluster.settings ` object at the time
652- [ ` .setupParent () ` ] [ ] was called and is advisory only, since multiple calls to
653- [ ` .setupParent () ` ] [ ] can be made in a single tick.
653+ [ ` .setupPrimary () ` ] [ ] was called and is advisory only, since multiple calls to
654+ [ ` .setupPrimary () ` ] [ ] can be made in a single tick.
654655
655656If accuracy is important, use ` cluster.settings ` .
656657
@@ -665,12 +666,12 @@ added: v0.7.7
665666Calls ` .disconnect() ` on each worker in ` cluster.workers ` .
666667
667668When they are disconnected all internal handles will be closed, allowing the
668- parent process to die gracefully if no other event is waiting.
669+ primary process to die gracefully if no other event is waiting.
669670
670671The method takes an optional callback argument which will be called when
671672finished.
672673
673- This can only be called from the parent process.
674+ This can only be called from the primary process.
674675
675676## ` cluster.fork([env]) `
676677<!-- YAML
@@ -682,26 +683,26 @@ added: v0.6.0
682683
683684Spawn a new worker process.
684685
685- This can only be called from the parent process.
686+ This can only be called from the primary process.
686687
687688## ` cluster.isMaster `
688689<!-- YAML
689690added: v0.8.1
690691-->
691692
692- Deprecated alias for isMaster, see isParent for more
693+ Deprecated alias for isMaster, see isPrimary for more
693694details.
694695
695- ## ` cluster.isParent `
696+ ## ` cluster.isPrimary `
696697<!-- YAML
697698added: REPLACEME
698699-->
699700
700701* {boolean}
701702
702- True if the process is a parent . This is determined
703+ True if the process is a primary . This is determined
703704by the ` process.env.NODE_UNIQUE_ID ` . If ` process.env.NODE_UNIQUE_ID ` is
704- undefined, then ` isParent ` is ` true ` .
705+ undefined, then ` isPrimary ` is ` true ` .
705706
706707## ` cluster.isWorker `
707708<!-- YAML
@@ -710,7 +711,7 @@ added: v0.6.0
710711
711712* {boolean}
712713
713- True if the process is not a parent (it is the negation of ` cluster.isParent ` ).
714+ True if the process is not a primary (it is the negation of ` cluster.isPrimary ` ).
714715
715716## ` cluster.schedulingPolicy `
716717<!-- YAML
@@ -720,7 +721,7 @@ added: v0.11.2
720721The scheduling policy, either ` cluster.SCHED_RR ` for round-robin or
721722` cluster.SCHED_NONE ` to leave it to the operating system. This is a
722723global setting and effectively frozen once either the first worker is spawned,
723- or [ ` .setupParent () ` ] [ ] is called, whichever comes first.
724+ or [ ` .setupPrimary () ` ] [ ] is called, whichever comes first.
724725
725726` SCHED_RR ` is the default on all operating systems except Windows.
726727Windows will change to ` SCHED_RR ` once libuv is able to effectively
@@ -775,11 +776,11 @@ changes:
775776 * ` inspectPort ` {number|Function} Sets inspector port of worker.
776777 This can be a number, or a function that takes no arguments and returns a
777778 number. By default each worker gets its own port, incremented from the
778- parent 's ` process.debugPort ` .
779+ primary 's ` process.debugPort ` .
779780 * ` windowsHide ` {boolean} Hide the forked processes console window that would
780781 normally be created on Windows systems. ** Default:** ` false ` .
781782
782- After calling [ ` .setupParent () ` ] [ ] (or [ ` .fork() ` ] [ ] ) this settings object will
783+ After calling [ ` .setupPrimary () ` ] [ ] (or [ ` .fork() ` ] [ ] ) this settings object will
783784contain the settings, including the default values.
784785
785786This object is not intended to be changed or set manually.
@@ -793,44 +794,44 @@ changes:
793794 description: The `stdio` option is supported now.
794795-->
795796
796- Deprecated alias for setupParent , see setupParent
797+ Deprecated alias for setupPrimary , see setupPrimary
797798for more details.
798799
799- ## ` cluster.setupParent ([settings]) `
800+ ## ` cluster.setupPrimary ([settings]) `
800801<!-- YAML
801802added: REPLACEME
802803-->
803804
804805* ` settings ` {Object} See [ ` cluster.settings ` ] [ ] .
805806
806- ` setupParent ` is used to change the default 'fork' behavior. Once called,
807+ ` setupPrimary ` is used to change the default 'fork' behavior. Once called,
807808the settings will be present in ` cluster.settings ` .
808809
809810Any settings changes only affect future calls to [ ` .fork() ` ] [ ] and have no
810811effect on workers that are already running.
811812
812- The only attribute of a worker that cannot be set via ` .setupParent () ` is
813+ The only attribute of a worker that cannot be set via ` .setupPrimary () ` is
813814the ` env ` passed to [ ` .fork() ` ] [ ] .
814815
815816The defaults above apply to the first call only; the defaults for later
816- calls are the current values at the time of ` cluster.setupParent () ` is called.
817+ calls are the current values at the time of ` cluster.setupPrimary () ` is called.
817818
818819``` js
819820const cluster = require (' cluster' );
820- cluster .setupParent ({
821+ cluster .setupPrimary ({
821822 exec: ' worker.js' ,
822823 args: [' --use' , ' https' ],
823824 silent: true
824825});
825826cluster .fork (); // https worker
826- cluster .setupParent ({
827+ cluster .setupPrimary ({
827828 exec: ' worker.js' ,
828829 args: [' --use' , ' http' ]
829830});
830831cluster .fork (); // http worker
831832```
832833
833- This can only be called from the parent process.
834+ This can only be called from the primary process.
834835
835836## ` cluster.worker `
836837<!-- YAML
@@ -839,13 +840,13 @@ added: v0.7.0
839840
840841* {Object}
841842
842- A reference to the current worker object. Not available in the parent process.
843+ A reference to the current worker object. Not available in the primary process.
843844
844845``` js
845846const cluster = require (' cluster' );
846847
847- if (cluster .isParent ) {
848- console .log (' I am parent ' );
848+ if (cluster .isPrimary ) {
849+ console .log (' I am primary ' );
849850 cluster .fork ();
850851 cluster .fork ();
851852} else if (cluster .isWorker ) {
@@ -861,7 +862,7 @@ added: v0.7.0
861862* {Object}
862863
863864A hash that stores the active worker objects, keyed by ` id ` field. Makes it
864- easy to loop through all the workers. It is only available in the parent
865+ easy to loop through all the workers. It is only available in the primary
865866process.
866867
867868A worker is removed from ` cluster.workers ` after the worker has disconnected
@@ -892,7 +893,7 @@ socket.on('data', (id) => {
892893[ Advanced serialization for `child_process` ] : child_process.md#child_process_advanced_serialization
893894[ Child Process module ] : child_process.md#child_process_child_process_fork_modulepath_args_options
894895[ `.fork()` ] : #cluster_cluster_fork_env
895- [ `.setupParent ()` ] : #cluster_cluster_setupparent_settings
896+ [ `.setupPrimary ()` ] : #cluster_cluster_setupprimary_settings
896897[ `ChildProcess.send()` ] : child_process.md#child_process_subprocess_send_message_sendhandle_options_callback
897898[ `child_process.fork()` ] : child_process.md#child_process_child_process_fork_modulepath_args_options
898899[ `child_process` event: `'exit'` ] : child_process.md#child_process_event_exit
0 commit comments