@@ -17,10 +17,10 @@ server ports.
17
17
``` mjs
18
18
import cluster from ' node:cluster' ;
19
19
import http from ' node:http' ;
20
- import { cpus } from ' node:os' ;
20
+ import { availableParallelism } from ' node:os' ;
21
21
import process from ' node:process' ;
22
22
23
- const numCPUs = cpus (). length ;
23
+ const numCPUs = availableParallelism () ;
24
24
25
25
if (cluster .isPrimary ) {
26
26
console .log (` Primary ${ process .pid } is running` );
@@ -48,7 +48,7 @@ if (cluster.isPrimary) {
48
48
``` cjs
49
49
const cluster = require (' node:cluster' );
50
50
const http = require (' node:http' );
51
- const numCPUs = require (' node:os' ).cpus (). length ;
51
+ const numCPUs = require (' node:os' ).availableParallelism () ;
52
52
const process = require (' node:process' );
53
53
54
54
if (cluster .isPrimary ) {
@@ -273,7 +273,7 @@ process of the number of HTTP requests received by the workers:
273
273
``` mjs
274
274
import cluster from ' node:cluster' ;
275
275
import http from ' node:http' ;
276
- import { cpus } from ' node:os' ;
276
+ import { availableParallelism } from ' node:os' ;
277
277
import process from ' node:process' ;
278
278
279
279
if (cluster .isPrimary ) {
@@ -292,7 +292,7 @@ if (cluster.isPrimary) {
292
292
}
293
293
294
294
// Start workers and listen for messages containing notifyRequest
295
- const numCPUs = cpus (). length ;
295
+ const numCPUs = availableParallelism () ;
296
296
for (let i = 0 ; i < numCPUs; i++ ) {
297
297
cluster .fork ();
298
298
}
@@ -335,7 +335,7 @@ if (cluster.isPrimary) {
335
335
}
336
336
337
337
// Start workers and listen for messages containing notifyRequest
338
- const numCPUs = require (' node:os' ).cpus (). length ;
338
+ const numCPUs = require (' node:os' ).availableParallelism () ;
339
339
for (let i = 0 ; i < numCPUs; i++ ) {
340
340
cluster .fork ();
341
341
}
@@ -507,10 +507,10 @@ because of exiting or being signaled). Otherwise, it returns `false`.
507
507
``` mjs
508
508
import cluster from ' node:cluster' ;
509
509
import http from ' node:http' ;
510
- import { cpus } from ' node:os' ;
510
+ import { availableParallelism } from ' node:os' ;
511
511
import process from ' node:process' ;
512
512
513
- const numCPUs = cpus (). length ;
513
+ const numCPUs = availableParallelism () ;
514
514
515
515
if (cluster .isPrimary ) {
516
516
console .log (` Primary ${ process .pid } is running` );
@@ -540,7 +540,7 @@ if (cluster.isPrimary) {
540
540
``` cjs
541
541
const cluster = require (' node:cluster' );
542
542
const http = require (' node:http' );
543
- const numCPUs = require (' node:os' ).cpus (). length ;
543
+ const numCPUs = require (' node:os' ).availableParallelism () ;
544
544
const process = require (' node:process' );
545
545
546
546
if (cluster .isPrimary ) {
0 commit comments