From: Jérôme Benoit Date: Sat, 22 Jul 2023 22:44:09 +0000 (+0200) Subject: build: improve maxWorkers computation X-Git-Tag: v2.6.21~37 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d5fdc57b2cec32c794ded94c86b93fcfb2308d21;p=poolifier.git build: improve maxWorkers computation Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index c88ada12..8819c592 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -1,5 +1,5 @@ -import crypto from 'crypto' -import fs from 'fs' +import crypto from 'node:crypto' +import fs from 'node:fs' import { DynamicClusterPool, DynamicThreadPool, diff --git a/rollup.config.mjs b/rollup.config.mjs index 28b89d86..e40f170d 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,15 +1,28 @@ -import { cpus } from 'node:os' +import * as os from 'node:os' import terser from '@rollup/plugin-terser' import typescript from '@rollup/plugin-typescript' import analyze from 'rollup-plugin-analyzer' import command from 'rollup-plugin-command' import del from 'rollup-plugin-delete' +const availableParallelism = () => { + let availableParallelism = 1 + try { + availableParallelism = os.availableParallelism() + } catch { + const numberOfCpus = os.cpus() + if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) { + availableParallelism = numberOfCpus.length + } + } + return availableParallelism +} + const isDevelopmentBuild = process.env.BUILD === 'development' const isAnalyzeBuild = process.env.ANALYZE const isDocumentationBuild = process.env.DOCUMENTATION -const maxWorkers = Math.floor(cpus().length / 2) +const maxWorkers = Math.floor(availableParallelism() / 2) export default { input: 'src/index.ts',