Skip to content

Commit 8e246a4

Browse files
Watch mode number of CPUs & documentation. (#8211)
* Watch mode number of CPUs & documentation. * Review feedback on code comment.
1 parent 5cde98e commit 8e246a4

File tree

7 files changed

+8
-7
lines changed

7 files changed

+8
-7
lines changed

docs/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Prevents Jest from executing more than the specified amount of tests at the same
214214

215215
### `--maxWorkers=<num>|<string>`
216216

217-
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.
217+
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.
218218

219219
For environments with variable CPUs available, you can use percentage based configuration: `--maxWorkers=50%`
220220

packages/jest-config/src/__tests__/getMaxWorkers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('getMaxWorkers', () => {
3232

3333
it('Returns based on the number of cpus', () => {
3434
expect(getMaxWorkers({})).toBe(3);
35-
expect(getMaxWorkers({watch: true})).toBe(3);
35+
expect(getMaxWorkers({watch: true})).toBe(2);
3636
});
3737

3838
describe('% based', () => {

packages/jest-config/src/getMaxWorkers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export default function getMaxWorkers(
3131

3232
return parsed > 0 ? parsed : 1;
3333
} else {
34+
// In watch mode, Jest should be unobtrusive and not use all available CPUs.
3435
const cpus = os.cpus() ? os.cpus().length : 1;
35-
return Math.max(cpus - 1, 1);
36+
return Math.max(argv.watch ? Math.floor(cpus / 2) : cpus - 1, 1);
3637
}
3738
}

website/versioned_docs/version-22.x/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together
184184

185185
### `--maxWorkers=<num>`
186186

187-
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.
187+
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.
188188

189189
### `--noStackTrace`
190190

website/versioned_docs/version-23.x/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together
196196

197197
### `--maxWorkers=<num>`
198198

199-
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.
199+
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.
200200

201201
### `--noStackTrace`
202202

website/versioned_docs/version-24.0/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together
211211

212212
### `--maxWorkers=<num>|<string>`
213213

214-
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.
214+
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.
215215

216216
For environments with variable CPUs available, you can use percentage based configuration: `--maxWorkers=50%`
217217

website/versioned_docs/version-24.1/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Prevents Jest from executing more than the specified amount of tests at the same
215215

216216
### `--maxWorkers=<num>|<string>`
217217

218-
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.
218+
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.
219219

220220
For environments with variable CPUs available, you can use percentage based configuration: `--maxWorkers=50%`
221221

0 commit comments

Comments
 (0)