Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61dbca2

Browse filesBrowse files
deokjinkimjuanarbol
authored andcommitted
doc: use os.availableParallelism() in async_context and cluster
Refs: #45895 PR-URL: #45979 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8c06e2f commit 61dbca2
Copy full SHA for 61dbca2

File tree

Expand file treeCollapse file tree

2 files changed

+11
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-11
lines changed
Open diff view settings
Collapse file

‎doc/api/async_context.md‎

Copy file name to clipboardExpand all lines: doc/api/async_context.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ This pool could be used as follows:
758758
import WorkerPool from './worker_pool.js';
759759
import os from 'node:os';
760760

761-
const pool = new WorkerPool(os.cpus().length);
761+
const pool = new WorkerPool(os.availableParallelism());
762762

763763
let finished = 0;
764764
for (let i = 0; i < 10; i++) {
@@ -774,7 +774,7 @@ for (let i = 0; i < 10; i++) {
774774
const WorkerPool = require('./worker_pool.js');
775775
const os = require('node:os');
776776

777-
const pool = new WorkerPool(os.cpus().length);
777+
const pool = new WorkerPool(os.availableParallelism());
778778

779779
let finished = 0;
780780
for (let i = 0; i < 10; i++) {
Collapse file

‎doc/api/cluster.md‎

Copy file name to clipboardExpand all lines: doc/api/cluster.md
+9-9Lines changed: 9 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ server ports.
1717
```mjs
1818
import cluster from 'node:cluster';
1919
import http from 'node:http';
20-
import { cpus } from 'node:os';
20+
import { availableParallelism } from 'node:os';
2121
import process from 'node:process';
2222

23-
const numCPUs = cpus().length;
23+
const numCPUs = availableParallelism();
2424

2525
if (cluster.isPrimary) {
2626
console.log(`Primary ${process.pid} is running`);
@@ -48,7 +48,7 @@ if (cluster.isPrimary) {
4848
```cjs
4949
const cluster = require('node:cluster');
5050
const http = require('node:http');
51-
const numCPUs = require('node:os').cpus().length;
51+
const numCPUs = require('node:os').availableParallelism();
5252
const process = require('node:process');
5353

5454
if (cluster.isPrimary) {
@@ -273,7 +273,7 @@ process of the number of HTTP requests received by the workers:
273273
```mjs
274274
import cluster from 'node:cluster';
275275
import http from 'node:http';
276-
import { cpus } from 'node:os';
276+
import { availableParallelism } from 'node:os';
277277
import process from 'node:process';
278278

279279
if (cluster.isPrimary) {
@@ -292,7 +292,7 @@ if (cluster.isPrimary) {
292292
}
293293

294294
// Start workers and listen for messages containing notifyRequest
295-
const numCPUs = cpus().length;
295+
const numCPUs = availableParallelism();
296296
for (let i = 0; i < numCPUs; i++) {
297297
cluster.fork();
298298
}
@@ -335,7 +335,7 @@ if (cluster.isPrimary) {
335335
}
336336

337337
// Start workers and listen for messages containing notifyRequest
338-
const numCPUs = require('node:os').cpus().length;
338+
const numCPUs = require('node:os').availableParallelism();
339339
for (let i = 0; i < numCPUs; i++) {
340340
cluster.fork();
341341
}
@@ -507,10 +507,10 @@ because of exiting or being signaled). Otherwise, it returns `false`.
507507
```mjs
508508
import cluster from 'node:cluster';
509509
import http from 'node:http';
510-
import { cpus } from 'node:os';
510+
import { availableParallelism } from 'node:os';
511511
import process from 'node:process';
512512

513-
const numCPUs = cpus().length;
513+
const numCPUs = availableParallelism();
514514

515515
if (cluster.isPrimary) {
516516
console.log(`Primary ${process.pid} is running`);
@@ -540,7 +540,7 @@ if (cluster.isPrimary) {
540540
```cjs
541541
const cluster = require('node:cluster');
542542
const http = require('node:http');
543-
const numCPUs = require('node:os').cpus().length;
543+
const numCPUs = require('node:os').availableParallelism();
544544
const process = require('node:process');
545545

546546
if (cluster.isPrimary) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.