mirror of https://github.com/actions/toolkit
Set default concurrency to 10 and make timeout configurable
parent
adb9c4a7f4
commit
f3c12d5561
|
@ -30,3 +30,19 @@ describe('isGhes', () => {
|
|||
expect(config.isGhes()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('uploadChunkTimeoutEnv', () => {
|
||||
it('should return default 300000 when no env set', () => {
|
||||
expect(config.getUploadChunkTimeout()).toBe(300000)
|
||||
})
|
||||
it('should return value set in ACTIONS_UPLOAD_TIMEOUT_MS', () => {
|
||||
process.env.ACTIONS_UPLOAD_TIMEOUT_MS = '150000'
|
||||
expect(config.getUploadChunkTimeout()).toBe(150000)
|
||||
})
|
||||
it('should throw if value set in ACTIONS_UPLOAD_TIMEOUT_MS is invalid', () => {
|
||||
process.env.ACTIONS_UPLOAD_TIMEOUT_MS = 'abc'
|
||||
expect(() => {
|
||||
config.getUploadChunkTimeout()
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -44,20 +44,21 @@ export function getGitHubWorkspaceDir(): string {
|
|||
return ghWorkspaceDir
|
||||
}
|
||||
|
||||
// Mimics behavior of azcopy: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-optimize
|
||||
// If your machine has fewer than 5 CPUs, then the value of this variable is set to 32.
|
||||
// Otherwise, the default value is equal to 16 multiplied by the number of CPUs. The maximum value of this variable is 300.
|
||||
// From testing, setting this value to 10 yielded best results in terms of reliability and there are no impact on performance either
|
||||
export function getConcurrency(): number {
|
||||
const numCPUs = os.cpus().length
|
||||
|
||||
if (numCPUs <= 4) {
|
||||
return 32
|
||||
}
|
||||
|
||||
const concurrency = 16 * numCPUs
|
||||
return concurrency > 300 ? 300 : concurrency
|
||||
return 10
|
||||
}
|
||||
|
||||
export function getUploadChunkTimeout(): number {
|
||||
return 300_000 // 5 minutes
|
||||
const timeoutVar = process.env['ACTIONS_UPLOAD_TIMEOUT_MS']
|
||||
if (!timeoutVar) {
|
||||
return 300000 // 5 minutes
|
||||
}
|
||||
|
||||
const timeout = parseInt(timeoutVar)
|
||||
if (isNaN(timeout)) {
|
||||
throw new Error('Invalid value set for ACTIONS_UPLOAD_TIMEOUT_MS env variable')
|
||||
}
|
||||
|
||||
return timeout
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue