From f3c12d55618ee99f7557a717ab9c899ca616873d Mon Sep 17 00:00:00 2001 From: Yang Cao Date: Wed, 8 Jan 2025 16:19:09 +0000 Subject: [PATCH] Set default concurrency to 10 and make timeout configurable --- packages/artifact/__tests__/config.test.ts | 16 ++++++++++++ .../artifact/src/internal/shared/config.ts | 25 ++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/packages/artifact/__tests__/config.test.ts b/packages/artifact/__tests__/config.test.ts index b9ef643c..11bbe396 100644 --- a/packages/artifact/__tests__/config.test.ts +++ b/packages/artifact/__tests__/config.test.ts @@ -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() + }) +}) diff --git a/packages/artifact/src/internal/shared/config.ts b/packages/artifact/src/internal/shared/config.ts index 047d3b98..75bbf8b5 100644 --- a/packages/artifact/src/internal/shared/config.ts +++ b/packages/artifact/src/internal/shared/config.ts @@ -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 }