1
0
Fork 0

Default upload artifacts concurrency to 5

pull/1962/head
Yang Cao 2025-02-20 16:55:54 +00:00
parent 2b08dc18f2
commit c26e6f3aba
2 changed files with 26 additions and 21 deletions

View File

@ -56,22 +56,30 @@ describe('uploadChunkTimeoutEnv', () => {
}) })
describe('uploadConcurrencyEnv', () => { describe('uploadConcurrencyEnv', () => {
it('should return default 32 when cpu num is <= 4', () => { it('Concurrency default to 5', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) ;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
expect(config.getConcurrency()).toBe(32) expect(config.getConcurrency()).toBe(5)
}) })
it('should return 16 * num of cpu when cpu num is > 4', () => { it('Concurrency max out at 300 on systems with many CPUs', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(6))
expect(config.getConcurrency()).toBe(96)
})
it('should return up to 300 max value', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(32)) ;(os.cpus as jest.Mock).mockReturnValue(new Array(32))
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '301'
expect(config.getConcurrency()).toBe(300) expect(config.getConcurrency()).toBe(300)
}) })
it('should return override value when ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is set', () => { it('Concurrency can be set to 32 when cpu num is <= 4', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '32'
expect(config.getConcurrency()).toBe(32)
})
it('Concurrency can be set 16 * num of cpu when cpu num is > 4', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(6))
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '96'
expect(config.getConcurrency()).toBe(96)
})
it('Concurrency can be overridden by env var ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) ;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '10' process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '10'
expect(config.getConcurrency()).toBe(10) expect(config.getConcurrency()).toBe(10)
@ -92,10 +100,4 @@ describe('uploadConcurrencyEnv', () => {
config.getConcurrency() config.getConcurrency()
}).toThrow() }).toThrow()
}) })
it('cannot go over currency cap when override value is greater', () => {
;(os.cpus as jest.Mock).mockReturnValue(new Array(4))
process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '40'
expect(config.getConcurrency()).toBe(32)
})
}) })

View File

@ -45,10 +45,8 @@ export function getGitHubWorkspaceDir(): string {
return ghWorkspaceDir return ghWorkspaceDir
} }
// Mimics behavior of azcopy: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-optimize // The maximum value of concurrency is 300.
// If your machine has fewer than 5 CPUs, then the value of this variable is set to 32. // This value can be changed with ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY variable.
// Otherwise, the default value is equal to 16 multiplied by the number of CPUs. The maximum value of this variable is 300.
// This value can be lowered with ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY variable.
export function getConcurrency(): number { export function getConcurrency(): number {
const numCPUs = os.cpus().length const numCPUs = os.cpus().length
let concurrencyCap = 32 let concurrencyCap = 32
@ -68,15 +66,20 @@ export function getConcurrency(): number {
} }
if (concurrency < concurrencyCap) { if (concurrency < concurrencyCap) {
info(
`Set concurrency based on the value set in ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY.`
)
return concurrency return concurrency
} }
info( info(
`ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is higher than the cap of ${concurrencyCap} based on the number of cpus. Lowering it to the cap.` `ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is higher than the cap of ${concurrencyCap} based on the number of cpus. Set it to the maximum value allowed.`
) )
return concurrencyCap
} }
return concurrencyCap // default concurrency to 5
return 5
} }
export function getUploadChunkTimeout(): number { export function getUploadChunkTimeout(): number {