Skip to content

Commit

Permalink
fix(ng-dev): limit the amount of CPUs used by workers (#436)
Browse files Browse the repository at this point in the history
Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.

This causes the task to be killed when formatting a large number of files due lack of resources.

https://app.circleci.com/pipelines/github/angular/angular-cli/20921/workflows/1f32e2ff-e726-41bc-a47c-9926f8b02f1d/jobs/290488

PR Close #436
  • Loading branch information
alan-agius4 authored and josephperrott committed Feb 28, 2022
1 parent ff24a8c commit 104c49a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ng-dev/format/run-commands-parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {info} from '../utils/console';

import {Formatter, FormatterAction, getActiveFormatters} from './formatters/index';

const AVAILABLE_THREADS = Math.max(cpus().length - 1, 1);
// Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
// This causes the task to be killed when formatting a large number of files due lack of resources.
// https://github.com/nodejs/node/issues/28762
const AVAILABLE_THREADS = Math.max(Math.min(cpus().length, 8) - 1, 1);

/** Interface describing a failure occurred during formatting of a file. */
export interface FormatFailure {
Expand Down
2 changes: 1 addition & 1 deletion tools/local-actions/changelog/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48561,7 +48561,7 @@ var require_run_commands_parallel = __commonJS({
var child_process_1 = require_child_process();
var console_1 = require_console();
var index_1 = require_formatters();
var AVAILABLE_THREADS = Math.max((0, os_1.cpus)().length - 1, 1);
var AVAILABLE_THREADS = Math.max(Math.min((0, os_1.cpus)().length, 8) - 1, 1);
function runFormatterInParallel(allFiles, action) {
return new Promise((resolve) => {
const formatters = (0, index_1.getActiveFormatters)();
Expand Down

0 comments on commit 104c49a

Please sign in to comment.