Skip to content

Commit 0719996

Browse files
author
Angular Builds
committed
94c753c1a fix(@angular-devkit/build-angular): limit the amount of CPUs used by workers
1 parent f41d5ab commit 0719996

File tree

8 files changed

+60
-15
lines changed

8 files changed

+60
-15
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "0.901.0-next.0+21.111e9cc",
3+
"version": "0.901.0-next.0+22.94c753c",
44
"description": "Angular Webpack Build Facade",
55
"experimental": true,
66
"main": "src/index.js",
77
"typings": "src/index.d.ts",
88
"builders": "builders.json",
99
"dependencies": {
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#111e9cc38",
11-
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#111e9cc38",
12-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#111e9cc38",
13-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#111e9cc38",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#94c753c1a",
11+
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#94c753c1a",
12+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#94c753c1a",
13+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#94c753c1a",
1414
"@babel/core": "7.8.4",
1515
"@babel/preset-env": "7.8.4",
1616
"@babel/template": "7.8.3",
17-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#111e9cc38",
17+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#94c753c1a",
1818
"ajv": "6.12.0",
1919
"autoprefixer": "9.7.4",
2020
"babel-loader": "8.0.6",

src/angular-cli-files/models/webpack-configs/common.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const build_optimizer_1 = require("@angular-devkit/build-optimizer");
1111
const core_1 = require("@angular-devkit/core");
1212
const CopyWebpackPlugin = require("copy-webpack-plugin");
1313
const fs_1 = require("fs");
14-
const os_1 = require("os");
1514
const path = require("path");
1615
const typescript_1 = require("typescript");
1716
const webpack_1 = require("webpack");
@@ -331,14 +330,9 @@ function getCommonConfig(wco) {
331330
// Name mangling is handled within the browser builder
332331
mangle: environment_options_1.allowMangle && buildOptions.platform !== 'server' && !differentialLoadingMode,
333332
};
334-
// Use up to 7 CPUs for Terser workers, but no more.
335-
// Some environments, like CircleCI, report a large number of CPUs but trying to use them
336-
// Will cause `Error: Call retries were exceeded` errors.
337-
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
338-
const maxCpus = Math.min(os_1.cpus().length, 7);
339333
extraMinimizers.push(new TerserPlugin({
340334
sourceMap: scriptsSourceMap,
341-
parallel: maxCpus,
335+
parallel: utils_1.maxWorkers,
342336
cache: !environment_options_1.cachingDisabled && cache_path_1.findCachePath('terser-webpack'),
343337
extractComments: false,
344338
chunkFilter: (chunk) => !globalScriptsByBundleName.some(s => s.bundleName === chunk.name),
@@ -348,7 +342,7 @@ function getCommonConfig(wco) {
348342
// They are shared between ES2015 & ES5 outputs so must support ES5.
349343
new TerserPlugin({
350344
sourceMap: scriptsSourceMap,
351-
parallel: maxCpus,
345+
parallel: utils_1.maxWorkers,
352346
cache: !environment_options_1.cachingDisabled && cache_path_1.findCachePath('terser-webpack'),
353347
extractComments: false,
354348
chunkFilter: (chunk) => globalScriptsByBundleName.some(s => s.bundleName === chunk.name),

src/utils/action-executor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const os = require("os");
1212
const path = require("path");
1313
const v8 = require("v8");
1414
const action_cache_1 = require("./action-cache");
15+
const workers_1 = require("./workers");
1516
const hasThreadSupport = (() => {
1617
try {
1718
require('worker_threads');
@@ -49,6 +50,7 @@ class BundleActionExecutor {
4950
return (this.largeWorker = new jest_worker_1.default(workerFile, {
5051
exposedMethods: ['process', 'inlineLocales'],
5152
setupArgs: [[...serialize(this.workerOptions)]],
53+
numWorkers: workers_1.maxWorkers,
5254
}));
5355
}
5456
ensureSmall() {

src/utils/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './normalize-source-maps';
1515
export * from './normalize-optimization';
1616
export * from './normalize-builder-schema';
1717
export * from './url';
18+
export * from './workers';

src/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ __export(require("./normalize-source-maps"));
2020
__export(require("./normalize-optimization"));
2121
__export(require("./normalize-builder-schema"));
2222
__export(require("./url"));
23+
__export(require("./workers"));

src/utils/workers.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
/**
9+
* Use CPU count -1 with limit to 7 for workers not to clog the system.
10+
* Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
11+
* This cause `Error: Call retries were exceeded` errors when trying to use them.
12+
*
13+
* See:
14+
*
15+
* https://github.com/nodejs/node/issues/28762
16+
*
17+
* https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
18+
*
19+
* https://github.com/angular/angular-cli/issues/16860#issuecomment-588828079
20+
*
21+
*/
22+
export declare const maxWorkers: number;

src/utils/workers.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
/**
3+
* @license
4+
* Copyright Google Inc. All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.io/license
8+
*/
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
const os_1 = require("os");
11+
/**
12+
* Use CPU count -1 with limit to 7 for workers not to clog the system.
13+
* Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
14+
* This cause `Error: Call retries were exceeded` errors when trying to use them.
15+
*
16+
* See:
17+
*
18+
* https://github.com/nodejs/node/issues/28762
19+
*
20+
* https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
21+
*
22+
* https://github.com/angular/angular-cli/issues/16860#issuecomment-588828079
23+
*
24+
*/
25+
exports.maxWorkers = Math.max(Math.min(os_1.cpus().length, 8) - 1, 1);

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Tue Feb 25 2020 19:04:22 GMT+0000 (Coordinated Universal Time)
1+
Tue Feb 25 2020 19:08:31 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)