From 4c3f289c1977b05e6d8e784a804b9f5319c3ec2d Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sat, 27 Jul 2024 13:05:17 +0300 Subject: [PATCH] fix: always use half of available parallelism (#611) * fix: always use half of available parallelism * fix fallback docs * revert docs * tweak logic --- src/polyfills/cpus.ts | 4 ++-- src/services/run-tests.ts | 3 ++- website/docs/documentation/poku/options/concurrency.mdx | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/polyfills/cpus.ts b/src/polyfills/cpus.ts index 633ee74e..d1bf05ee 100644 --- a/src/polyfills/cpus.ts +++ b/src/polyfills/cpus.ts @@ -5,5 +5,5 @@ import { export const availableParallelism = (): number => typeof nodeAvailableParallelism === 'function' - ? Math.floor(nodeAvailableParallelism() / 2) - : (cpus()?.length ?? 1); + ? nodeAvailableParallelism() + : (cpus()?.length ?? 0); diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index 27138846..03568042 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -97,7 +97,8 @@ export const runTestsParallel = async ( ? [sanitizePath(dir)] : await listFiles(testDir, configs); const filesByConcurrency: string[][] = []; - const concurrencyLimit = configs?.concurrency ?? availableParallelism(); + const concurrencyLimit = + configs?.concurrency ?? Math.max(Math.floor(availableParallelism() / 2), 1); const concurrencyResults: (boolean | undefined)[][] = []; const showLogs = !isQuiet(configs); diff --git a/website/docs/documentation/poku/options/concurrency.mdx b/website/docs/documentation/poku/options/concurrency.mdx index 252a70b5..e24cfb78 100644 --- a/website/docs/documentation/poku/options/concurrency.mdx +++ b/website/docs/documentation/poku/options/concurrency.mdx @@ -5,7 +5,8 @@ sidebar_position: 8 # `concurrency` When using `parallel` option, use `concurrency` to limit the number of tests running concurrently.
-The default value is `0` (no limit). +The default value is half of the available cores. When available, the `os.availableParallelism()` method is used. Otherwise Poku looks at the `os.cpus().length` or sets the value to `1`.
+To allow unlimited parallelism set the value to `0`. ## CLI