Skip to content

Commit

Permalink
doc: use os.availableParallelism() in async_context and cluster
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
deokjinkim authored and juanarbol committed Jan 31, 2023
1 parent 8c06e2f commit 61dbca2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions doc/api/async_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ This pool could be used as follows:
import WorkerPool from './worker_pool.js';
import os from 'node:os';

const pool = new WorkerPool(os.cpus().length);
const pool = new WorkerPool(os.availableParallelism());

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

const pool = new WorkerPool(os.cpus().length);
const pool = new WorkerPool(os.availableParallelism());

let finished = 0;
for (let i = 0; i < 10; i++) {
Expand Down
18 changes: 9 additions & 9 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ server ports.
```mjs
import cluster from 'node:cluster';
import http from 'node:http';
import { cpus } from 'node:os';
import { availableParallelism } from 'node:os';
import process from 'node:process';

const numCPUs = cpus().length;
const numCPUs = availableParallelism();

if (cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`);
Expand Down Expand Up @@ -48,7 +48,7 @@ if (cluster.isPrimary) {
```cjs
const cluster = require('node:cluster');
const http = require('node:http');
const numCPUs = require('node:os').cpus().length;
const numCPUs = require('node:os').availableParallelism();
const process = require('node:process');

if (cluster.isPrimary) {
Expand Down Expand Up @@ -273,7 +273,7 @@ process of the number of HTTP requests received by the workers:
```mjs
import cluster from 'node:cluster';
import http from 'node:http';
import { cpus } from 'node:os';
import { availableParallelism } from 'node:os';
import process from 'node:process';

if (cluster.isPrimary) {
Expand All @@ -292,7 +292,7 @@ if (cluster.isPrimary) {
}

// Start workers and listen for messages containing notifyRequest
const numCPUs = cpus().length;
const numCPUs = availableParallelism();
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
Expand Down Expand Up @@ -335,7 +335,7 @@ if (cluster.isPrimary) {
}

// Start workers and listen for messages containing notifyRequest
const numCPUs = require('node:os').cpus().length;
const numCPUs = require('node:os').availableParallelism();
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
Expand Down Expand Up @@ -507,10 +507,10 @@ because of exiting or being signaled). Otherwise, it returns `false`.
```mjs
import cluster from 'node:cluster';
import http from 'node:http';
import { cpus } from 'node:os';
import { availableParallelism } from 'node:os';
import process from 'node:process';

const numCPUs = cpus().length;
const numCPUs = availableParallelism();

if (cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`);
Expand Down Expand Up @@ -540,7 +540,7 @@ if (cluster.isPrimary) {
```cjs
const cluster = require('node:cluster');
const http = require('node:http');
const numCPUs = require('node:os').cpus().length;
const numCPUs = require('node:os').availableParallelism();
const process = require('node:process');

if (cluster.isPrimary) {
Expand Down

0 comments on commit 61dbca2

Please sign in to comment.