Skip to content

Commit 6eb13d7

Browse files
authored
Merge pull request microsoft#565 from christiango/chrisgo/max-parallel
Add support for using all cores on windows machines with -p max flag
2 parents 8ca9e59 + ec6b618 commit 6eb13d7

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

‎apps/rush-lib/src/cli/actions/CustomRushAction.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import {
1818
CommandLineFlagParameter,
19-
CommandLineIntegerParameter,
19+
CommandLineStringParameter,
2020
CommandLineStringListParameter,
2121
CommandLineOptionParameter,
2222
ICommandLineActionOptions
@@ -39,7 +39,7 @@ export class CustomRushAction extends BaseRushAction {
3939
private _fromFlag: CommandLineStringListParameter;
4040
private _toFlag: CommandLineStringListParameter;
4141
private _verboseParameter: CommandLineFlagParameter;
42-
private _parallelismParameter: CommandLineIntegerParameter | undefined;
42+
private _parallelismParameter: CommandLineStringParameter | undefined;
4343

4444
constructor(private _parser: RushCommandLineParser,
4545
options: ICommandLineActionOptions,
@@ -75,9 +75,9 @@ export class CustomRushAction extends BaseRushAction {
7575

7676
// if this is parallizable, then use the value from the flag (undefined or a number),
7777
// if this is not parallelized, then use 1 core
78-
const parallelism: number | undefined = this._isParallelized()
78+
const parallelism: string | undefined = this._isParallelized()
7979
? this._parallelismParameter!.value
80-
: 1;
80+
: '1';
8181

8282
// collect all custom flags here
8383
const customFlags: string[] = [];
@@ -127,12 +127,13 @@ export class CustomRushAction extends BaseRushAction {
127127

128128
protected onDefineParameters(): void {
129129
if (this._isParallelized()) {
130-
this._parallelismParameter = this.defineIntegerParameter({
130+
this._parallelismParameter = this.defineStringParameter({
131131
parameterLongName: '--parallelism',
132132
parameterShortName: '-p',
133133
key: 'COUNT',
134-
description: 'Specify the number of concurrent build processes.'
135-
+ ' If omitted, the parallelism will be based on the number of CPU cores.'
134+
description: 'Specify the number of concurrent build processes'
135+
+ ' The value "max" can be specified to indicate the number of CPU cores.'
136+
+ ' If this parameter omitted, the default value depends on the operating system and number of CPU cores.'
136137
});
137138
}
138139
this._toFlag = this.defineStringListParameter({

‎apps/rush-lib/src/cli/logic/TaskSelector.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ITaskSelectorConstructor {
1515
commandToRun: string;
1616
customFlags: string[];
1717
isQuietMode: boolean;
18-
parallelism: number;
18+
parallelism: string;
1919
isIncrementalBuildAllowed: boolean;
2020
changedProjectsOnly: boolean;
2121
}

‎apps/rush-lib/src/cli/taskRunner/TaskRunner.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,36 @@ export default class TaskRunner {
3131
private _completedTasks: number;
3232

3333
constructor(quietMode: boolean,
34-
parallelism: number | undefined,
34+
parallelism: string |undefined,
3535
changedProjectsOnly: boolean) {
3636
this._tasks = new Map<string, ITask>();
3737
this._buildQueue = [];
3838
this._quietMode = quietMode;
3939
this._hasAnyFailures = false;
4040
this._changedProjectsOnly = changedProjectsOnly;
4141

42+
const numberOfCores: number = os.cpus().length;
43+
4244
if (parallelism) {
43-
this._parallelism = parallelism;
44-
} else {
45+
if (parallelism === 'max') {
46+
this._parallelism = numberOfCores;
47+
} else {
48+
const parallelismInt: number = parseInt(parallelism, 10);
49+
50+
if (isNaN(parallelismInt)) {
51+
throw new Error(`Invalid parallelism value of '${parallelism}', expected a number or 'max'`);
52+
}
53+
54+
this._parallelism = parallelismInt;
55+
}
56+
57+
} else {
4558
// If an explicit parallelism number wasn't provided, then choose a sensible
4659
// default.
47-
const numberOfCores: number = os.cpus().length;
48-
4960
if (os.platform() === 'win32') {
5061
// On desktop Windows, some people have complained that their system becomes
5162
// sluggish if Rush is using all the CPU cores. Leave one thread for
52-
// other operations.
63+
// other operations. For CI environments, you can use the "max" argument to use all available cores.
5364
this._parallelism = Math.max(numberOfCores - 1, 1);
5465
} else {
5566
// Unix-like operating systems have more balanced scheduling, so default
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Add support for overriding the default windows parallelism with 'max'.",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "christiango@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)