Skip to content

Commit

Permalink
Watch mode number of CPUs & documentation. (#8211)
Browse files Browse the repository at this point in the history
* Watch mode number of CPUs & documentation.

* Review feedback on code comment.
  • Loading branch information
scotthovestadt committed Mar 25, 2019
1 parent 5cde98e commit 8e246a4
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Prevents Jest from executing more than the specified amount of tests at the same

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

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%`

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/__tests__/getMaxWorkers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-config/src/getMaxWorkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion website/versioned_docs/version-22.x/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together

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

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`

Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-23.x/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together

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

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`

Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-24.0/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Logs the heap usage after every test. Useful to debug memory leaks. Use together

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

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%`

Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-24.1/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Prevents Jest from executing more than the specified amount of tests at the same

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

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%`

Expand Down

0 comments on commit 8e246a4

Please sign in to comment.