-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: workspace-concurrency based on cores amount (#3574)
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@pnpm/config": minor | ||
--- | ||
|
||
Add `workspace-concurrency` based on CPU cores amount, just set `workspace-concurrency` as zero or negative, the concurrency limit is set as `max((amount of cores) - abs(workspace-concurrency), 1)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { cpus } from 'os' | ||
|
||
export function getWorkspaceConcurrency (option: number | undefined): number { | ||
if (typeof option !== 'number') return 4 | ||
|
||
if (option <= 0) { | ||
// If option is <= 0, it uses the amount of cores minus the absolute of the number given | ||
// but always returning at least 1 | ||
return Math.max(1, cpus().length - Math.abs(option)) | ||
} | ||
|
||
return option | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { cpus } from 'os' | ||
import { getWorkspaceConcurrency } from '../lib/concurrency' | ||
|
||
const hostCores = cpus().length | ||
|
||
test('default workspace concurrency', () => { | ||
const n = getWorkspaceConcurrency(undefined) | ||
|
||
expect(n).toBe(4) | ||
}) | ||
|
||
test('get back positive amount', () => { | ||
expect(getWorkspaceConcurrency(5)).toBe(5) | ||
}) | ||
|
||
test('match host cores amount', () => { | ||
const n = getWorkspaceConcurrency(0) | ||
|
||
expect(n).toBe(hostCores) | ||
}) | ||
|
||
test('host cores minus X', () => { | ||
const n1 = getWorkspaceConcurrency(-1) | ||
|
||
expect(n1).toBe(Math.max(1, hostCores - 1)) | ||
|
||
const n2 = getWorkspaceConcurrency(-9999) | ||
|
||
expect(n2).toBe(1) | ||
}) |