From 2747363dc7670a0997e028165589d68f880e5592 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Thu, 29 Dec 2022 10:38:04 +0900 Subject: [PATCH 1/2] test: use `os.availableParallelism()` Refs: https://github.com/nodejs/node/pull/45895 --- test/parallel/test-cluster-concurrent-disconnect.js | 2 +- test/parallel/test-gc-http-client-connaborted.js | 2 +- test/parallel/test-gc-net-timeout.js | 2 +- test/parallel/test-worker-memory.js | 2 +- test/pummel/test-policy-integrity-dep.js | 2 +- test/pummel/test-policy-integrity-parent-commonjs.js | 2 +- test/pummel/test-policy-integrity-parent-module.js | 2 +- test/pummel/test-policy-integrity-parent-no-package-json.js | 2 +- test/pummel/test-policy-integrity-worker-commonjs.js | 2 +- test/pummel/test-policy-integrity-worker-module.js | 2 +- test/pummel/test-policy-integrity-worker-no-package-json.js | 2 +- test/sequential/test-gc-http-client-onerror.js | 2 +- test/sequential/test-gc-http-client-timeout.js | 2 +- test/sequential/test-gc-http-client.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-cluster-concurrent-disconnect.js b/test/parallel/test-cluster-concurrent-disconnect.js index e3771a0a4fdcb0..c2ba7b43447733 100644 --- a/test/parallel/test-cluster-concurrent-disconnect.js +++ b/test/parallel/test-cluster-concurrent-disconnect.js @@ -10,7 +10,7 @@ const os = require('os'); if (cluster.isPrimary) { const workers = []; - const numCPUs = os.cpus().length; + const numCPUs = os.availableParallelism(); let waitOnline = numCPUs; for (let i = 0; i < numCPUs; i++) { const worker = cluster.fork(); diff --git a/test/parallel/test-gc-http-client-connaborted.js b/test/parallel/test-gc-http-client-connaborted.js index fd276d30e2beb1..e9282653f2c132 100644 --- a/test/parallel/test-gc-http-client-connaborted.js +++ b/test/parallel/test-gc-http-client-connaborted.js @@ -8,7 +8,7 @@ const onGC = require('../common/ongc'); const http = require('http'); const os = require('os'); -const cpus = os.cpus().length; +const cpus = os.availableParallelism(); let createClients = true; let done = 0; let count = 0; diff --git a/test/parallel/test-gc-net-timeout.js b/test/parallel/test-gc-net-timeout.js index 6b9d51c98d0e84..dfb2bbfd92ac55 100644 --- a/test/parallel/test-gc-net-timeout.js +++ b/test/parallel/test-gc-net-timeout.js @@ -26,7 +26,7 @@ function serverHandler(sock) { }, 100); } -const cpus = os.cpus().length; +const cpus = os.availableParallelism(); let createClients = true; let done = 0; let count = 0; diff --git a/test/parallel/test-worker-memory.js b/test/parallel/test-worker-memory.js index 19b89d4321d6d7..8c38409a26bab1 100644 --- a/test/parallel/test-worker-memory.js +++ b/test/parallel/test-worker-memory.js @@ -7,7 +7,7 @@ const assert = require('assert'); const util = require('util'); const { Worker } = require('worker_threads'); -let numWorkers = +process.env.JOBS || require('os').cpus().length; +let numWorkers = +process.env.JOBS || require('os').availableParallelism(); if (numWorkers > 20) { // Cap the number of workers at 20 (as an even divisor of 60 used as // the total number of workers started) otherwise the test fails on diff --git a/test/pummel/test-policy-integrity-dep.js b/test/pummel/test-policy-integrity-dep.js index 02f24d02a23544..cbccc60cdb4468 100644 --- a/test/pummel/test-policy-integrity-dep.js +++ b/test/pummel/test-policy-integrity-dep.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/pummel/test-policy-integrity-parent-commonjs.js b/test/pummel/test-policy-integrity-parent-commonjs.js index 425abe38ebd9fb..2e77786e3b925f 100644 --- a/test/pummel/test-policy-integrity-parent-commonjs.js +++ b/test/pummel/test-policy-integrity-parent-commonjs.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/pummel/test-policy-integrity-parent-module.js b/test/pummel/test-policy-integrity-parent-module.js index dda800dc3652fc..1c1c8cbbb47cd8 100644 --- a/test/pummel/test-policy-integrity-parent-module.js +++ b/test/pummel/test-policy-integrity-parent-module.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/pummel/test-policy-integrity-parent-no-package-json.js b/test/pummel/test-policy-integrity-parent-no-package-json.js index a722263e1e484a..012b2228d3eb98 100644 --- a/test/pummel/test-policy-integrity-parent-no-package-json.js +++ b/test/pummel/test-policy-integrity-parent-no-package-json.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/pummel/test-policy-integrity-worker-commonjs.js b/test/pummel/test-policy-integrity-worker-commonjs.js index b5d49222a2f01c..bfa24cd8fd407b 100644 --- a/test/pummel/test-policy-integrity-worker-commonjs.js +++ b/test/pummel/test-policy-integrity-worker-commonjs.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/pummel/test-policy-integrity-worker-module.js b/test/pummel/test-policy-integrity-worker-module.js index a8a4fb2c29589f..e51e24be45883e 100644 --- a/test/pummel/test-policy-integrity-worker-module.js +++ b/test/pummel/test-policy-integrity-worker-module.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/pummel/test-policy-integrity-worker-no-package-json.js b/test/pummel/test-policy-integrity-worker-no-package-json.js index e5b3e3ccfabbf6..c1cfa22eb694ed 100644 --- a/test/pummel/test-policy-integrity-worker-no-package-json.js +++ b/test/pummel/test-policy-integrity-worker-no-package-json.js @@ -22,7 +22,7 @@ const fs = require('fs'); const path = require('path'); const { pathToFileURL } = require('url'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function hash(algo, body) { const values = []; diff --git a/test/sequential/test-gc-http-client-onerror.js b/test/sequential/test-gc-http-client-onerror.js index d5ae7fbd20c156..7574c0f9373634 100644 --- a/test/sequential/test-gc-http-client-onerror.js +++ b/test/sequential/test-gc-http-client-onerror.js @@ -6,7 +6,7 @@ const common = require('../common'); const onGC = require('../common/ongc'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function serverHandler(req, res) { req.resume(); diff --git a/test/sequential/test-gc-http-client-timeout.js b/test/sequential/test-gc-http-client-timeout.js index 3472e79422d081..51dec7f043182d 100644 --- a/test/sequential/test-gc-http-client-timeout.js +++ b/test/sequential/test-gc-http-client-timeout.js @@ -16,7 +16,7 @@ function serverHandler(req, res) { }, 100); } -const cpus = os.cpus().length; +const cpus = os.availableParallelism(); const numRequests = 36; let createClients = true; let done = 0; diff --git a/test/sequential/test-gc-http-client.js b/test/sequential/test-gc-http-client.js index 34f565c315d454..8e9d3e9e729db2 100644 --- a/test/sequential/test-gc-http-client.js +++ b/test/sequential/test-gc-http-client.js @@ -5,7 +5,7 @@ const common = require('../common'); const onGC = require('../common/ongc'); -const cpus = require('os').cpus().length; +const cpus = require('os').availableParallelism(); function serverHandler(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); From 35a551e2c2b77d03f969063ae43fb7c7b1252e54 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Mon, 2 Jan 2023 13:15:37 +0900 Subject: [PATCH 2/2] benchmark,tools: use os.availableParallelism() Refs: https://github.com/nodejs/node/pull/45895 --- benchmark/_http-benchmarkers.js | 2 +- tools/build-addons.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index ec0e80a9e7edbe..e8c5ee7711ab33 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -65,7 +65,7 @@ class WrkBenchmarker { const args = [ '-d', duration, '-c', options.connections, - '-t', Math.min(options.connections, require('os').cpus().length || 8), + '-t', Math.min(options.connections, require('os').availableParallelism() || 8), `${scheme}://127.0.0.1:${options.port}${options.path}`, ]; for (const field in options.headers) { diff --git a/tools/build-addons.mjs b/tools/build-addons.mjs index b0ec02d8e90cba..a96c18435ddc03 100755 --- a/tools/build-addons.mjs +++ b/tools/build-addons.mjs @@ -11,7 +11,7 @@ import os from 'node:os'; const execFile = util.promisify(child_process.execFile); -const parallelization = +process.env.JOBS || os.cpus().length; +const parallelization = +process.env.JOBS || os.availableParallelism(); const nodeGyp = process.argv[2]; const directory = process.argv[3];