Skip to content

Commit

Permalink
revert change to max worker count
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Aug 11, 2020
1 parent 4fd4301 commit 054913c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
16 changes: 8 additions & 8 deletions packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('OptimizerConfig::parseOptions()', () => {
"filters": Array [],
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 3,
"maxWorkerCount": 2,
"outputRoot": <absolute path>,
"pluginPaths": Array [],
"pluginScanDirs": Array [
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('OptimizerConfig::parseOptions()', () => {
"filters": Array [],
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 3,
"maxWorkerCount": 2,
"outputRoot": <absolute path>,
"pluginPaths": Array [],
"pluginScanDirs": Array [
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('OptimizerConfig::parseOptions()', () => {
"filters": Array [],
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 3,
"maxWorkerCount": 2,
"outputRoot": <absolute path>,
"pluginPaths": Array [],
"pluginScanDirs": Array [
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('OptimizerConfig::parseOptions()', () => {
"filters": Array [],
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 3,
"maxWorkerCount": 2,
"outputRoot": <absolute path>,
"pluginPaths": Array [],
"pluginScanDirs": Array [
Expand All @@ -234,7 +234,7 @@ describe('OptimizerConfig::parseOptions()', () => {
"filters": Array [],
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 3,
"maxWorkerCount": 2,
"outputRoot": <absolute path>,
"pluginPaths": Array [],
"pluginScanDirs": Array [
Expand Down Expand Up @@ -449,7 +449,7 @@ describe('OptimizerConfig::create()', () => {
[Window],
],
"invocationCallOrder": Array [
15,
21,
],
"results": Array [
Object {
Expand All @@ -475,7 +475,7 @@ describe('OptimizerConfig::create()', () => {
[Window],
],
"invocationCallOrder": Array [
17,
23,
],
"results": Array [
Object {
Expand All @@ -499,7 +499,7 @@ describe('OptimizerConfig::create()', () => {
[Window],
],
"invocationCallOrder": Array [
16,
22,
],
"results": Array [
Object {
Expand Down
14 changes: 9 additions & 5 deletions packages/kbn-optimizer/src/optimizer/optimizer_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ import { findKibanaPlatformPlugins, KibanaPlatformPlugin } from './kibana_platfo
import { getPluginBundles } from './get_plugin_bundles';
import { filterById } from './filter_by_id';

// don't break if cpus() returns nothing, or an empty array
const CPU_COUNT = Math.max(Os.cpus()?.length, 1);
// ensure we have at least three workers
const MAX_WORKER_COUNT = Math.max(CPU_COUNT - 1, 3);
function pickMaxWorkerCount(dist: boolean) {
// don't break if cpus() returns nothing, or an empty array
const cpuCount = Math.max(Os.cpus()?.length, 1);
// if we're buiding the dist then we can use more of the system's resources to get things done a little quicker
const maxWorkers = dist ? cpuCount - 1 : Math.ceil(cpuCount / 3);
// ensure we always have at least two workers
return Math.max(maxWorkers, 2);
}

function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
const result: any = {};
Expand Down Expand Up @@ -178,7 +182,7 @@ export class OptimizerConfig {

const maxWorkerCount = process.env.KBN_OPTIMIZER_MAX_WORKERS
? parseInt(process.env.KBN_OPTIMIZER_MAX_WORKERS, 10)
: options.maxWorkerCount ?? MAX_WORKER_COUNT;
: options.maxWorkerCount ?? pickMaxWorkerCount(dist);
if (typeof maxWorkerCount !== 'number' || !Number.isFinite(maxWorkerCount)) {
throw new TypeError('worker count must be a number');
}
Expand Down

0 comments on commit 054913c

Please sign in to comment.