From 8e246a4f60107cd9c6738b5f48d158ee634fa82c Mon Sep 17 00:00:00 2001 From: scotthovestadt Date: Mon, 25 Mar 2019 09:54:01 -0700 Subject: [PATCH] Watch mode number of CPUs & documentation. (#8211) * Watch mode number of CPUs & documentation. * Review feedback on code comment. --- docs/CLI.md | 2 +- packages/jest-config/src/__tests__/getMaxWorkers.test.ts | 2 +- packages/jest-config/src/getMaxWorkers.ts | 3 ++- website/versioned_docs/version-22.x/CLI.md | 2 +- website/versioned_docs/version-23.x/CLI.md | 2 +- website/versioned_docs/version-24.0/CLI.md | 2 +- website/versioned_docs/version-24.1/CLI.md | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index a681865c01ff..92b7e943441f 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -214,7 +214,7 @@ Prevents Jest from executing more than the specified amount of tests at the same ### `--maxWorkers=|` -Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases. +Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases. For environments with variable CPUs available, you can use percentage based configuration: `--maxWorkers=50%` diff --git a/packages/jest-config/src/__tests__/getMaxWorkers.test.ts b/packages/jest-config/src/__tests__/getMaxWorkers.test.ts index a4a92a419131..aab3290c5357 100644 --- a/packages/jest-config/src/__tests__/getMaxWorkers.test.ts +++ b/packages/jest-config/src/__tests__/getMaxWorkers.test.ts @@ -32,7 +32,7 @@ describe('getMaxWorkers', () => { it('Returns based on the number of cpus', () => { expect(getMaxWorkers({})).toBe(3); - expect(getMaxWorkers({watch: true})).toBe(3); + expect(getMaxWorkers({watch: true})).toBe(2); }); describe('% based', () => { diff --git a/packages/jest-config/src/getMaxWorkers.ts b/packages/jest-config/src/getMaxWorkers.ts index edf67a5de5d7..b96024477d6b 100644 --- a/packages/jest-config/src/getMaxWorkers.ts +++ b/packages/jest-config/src/getMaxWorkers.ts @@ -31,7 +31,8 @@ export default function getMaxWorkers( return parsed > 0 ? parsed : 1; } else { + // In watch mode, Jest should be unobtrusive and not use all available CPUs. const cpus = os.cpus() ? os.cpus().length : 1; - return Math.max(cpus - 1, 1); + return Math.max(argv.watch ? Math.floor(cpus / 2) : cpus - 1, 1); } } diff --git a/website/versioned_docs/version-22.x/CLI.md b/website/versioned_docs/version-22.x/CLI.md index 31ebc57e1b8f..6342983269a1 100644 --- a/website/versioned_docs/version-22.x/CLI.md +++ b/website/versioned_docs/version-22.x/CLI.md @@ -184,7 +184,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together ### `--maxWorkers=` -Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases. +Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases. ### `--noStackTrace` diff --git a/website/versioned_docs/version-23.x/CLI.md b/website/versioned_docs/version-23.x/CLI.md index 9da2e69747da..c5e70784dafe 100644 --- a/website/versioned_docs/version-23.x/CLI.md +++ b/website/versioned_docs/version-23.x/CLI.md @@ -196,7 +196,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together ### `--maxWorkers=` -Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases. +Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases. ### `--noStackTrace` diff --git a/website/versioned_docs/version-24.0/CLI.md b/website/versioned_docs/version-24.0/CLI.md index baad0beead40..549d569b2809 100644 --- a/website/versioned_docs/version-24.0/CLI.md +++ b/website/versioned_docs/version-24.0/CLI.md @@ -211,7 +211,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together ### `--maxWorkers=|` -Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases. +Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases. For environments with variable CPUs available, you can use percentage based configuration: `--maxWorkers=50%` diff --git a/website/versioned_docs/version-24.1/CLI.md b/website/versioned_docs/version-24.1/CLI.md index cf142c2cccec..b11918123a4f 100644 --- a/website/versioned_docs/version-24.1/CLI.md +++ b/website/versioned_docs/version-24.1/CLI.md @@ -215,7 +215,7 @@ Prevents Jest from executing more than the specified amount of tests at the same ### `--maxWorkers=|` -Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases. +Alias: `-w`. Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread. In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt. It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases. For environments with variable CPUs available, you can use percentage based configuration: `--maxWorkers=50%`