Skip to content

Commit f10f9c8

Browse files
authored
Merge pull request #1962 from actions/yacaovsnc/set_default_concurrency_to_5
Default upload artifacts concurrency to 5
2 parents 2b08dc1 + c26e6f3 commit f10f9c8

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

packages/artifact/__tests__/config.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,30 @@ describe('uploadChunkTimeoutEnv', () => {
5656
})
5757

5858
describe('uploadConcurrencyEnv', () => {
59-
it('should return default 32 when cpu num is <= 4', () => {
59+
it('Concurrency default to 5', () => {
6060
;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
61+
expect(config.getConcurrency()).toBe(5)
62+
})
63+
64+
it('Concurrency max out at 300 on systems with many CPUs', () => {
65+
;(os.cpus as jest.Mock).mockReturnValue(new Array(32))
66+
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '301'
67+
expect(config.getConcurrency()).toBe(300)
68+
})
69+
70+
it('Concurrency can be set to 32 when cpu num is <= 4', () => {
71+
;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
72+
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '32'
6173
expect(config.getConcurrency()).toBe(32)
6274
})
6375

64-
it('should return 16 * num of cpu when cpu num is > 4', () => {
76+
it('Concurrency can be set 16 * num of cpu when cpu num is > 4', () => {
6577
;(os.cpus as jest.Mock).mockReturnValue(new Array(6))
78+
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '96'
6679
expect(config.getConcurrency()).toBe(96)
6780
})
6881

69-
it('should return up to 300 max value', () => {
70-
;(os.cpus as jest.Mock).mockReturnValue(new Array(32))
71-
expect(config.getConcurrency()).toBe(300)
72-
})
73-
74-
it('should return override value when ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is set', () => {
82+
it('Concurrency can be overridden by env var ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY', () => {
7583
;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
7684
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '10'
7785
expect(config.getConcurrency()).toBe(10)
@@ -92,10 +100,4 @@ describe('uploadConcurrencyEnv', () => {
92100
config.getConcurrency()
93101
}).toThrow()
94102
})
95-
96-
it('cannot go over currency cap when override value is greater', () => {
97-
;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
98-
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '40'
99-
expect(config.getConcurrency()).toBe(32)
100-
})
101103
})

packages/artifact/src/internal/shared/config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ export function getGitHubWorkspaceDir(): string {
4545
return ghWorkspaceDir
4646
}
4747

48-
// Mimics behavior of azcopy: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-optimize
49-
// If your machine has fewer than 5 CPUs, then the value of this variable is set to 32.
50-
// Otherwise, the default value is equal to 16 multiplied by the number of CPUs. The maximum value of this variable is 300.
51-
// This value can be lowered with ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY variable.
48+
// The maximum value of concurrency is 300.
49+
// This value can be changed with ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY variable.
5250
export function getConcurrency(): number {
5351
const numCPUs = os.cpus().length
5452
let concurrencyCap = 32
@@ -68,15 +66,20 @@ export function getConcurrency(): number {
6866
}
6967

7068
if (concurrency < concurrencyCap) {
69+
info(
70+
`Set concurrency based on the value set in ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY.`
71+
)
7172
return concurrency
7273
}
7374

7475
info(
75-
`ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is higher than the cap of ${concurrencyCap} based on the number of cpus. Lowering it to the cap.`
76+
`ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is higher than the cap of ${concurrencyCap} based on the number of cpus. Set it to the maximum value allowed.`
7677
)
78+
return concurrencyCap
7779
}
7880

79-
return concurrencyCap
81+
// default concurrency to 5
82+
return 5
8083
}
8184

8285
export function getUploadChunkTimeout(): number {

0 commit comments

Comments
 (0)