|
| 1 | +import { randomBytes } from 'node:crypto' |
| 2 | +import fs from 'node:fs/promises' |
| 3 | +import path from 'node:path' |
| 4 | +import { restoreCache, saveCache } from '@actions/cache' |
| 5 | +import pLimit from 'p-limit' |
| 6 | + |
| 7 | +const TEMP_DIR = './benchmark' |
| 8 | + |
| 9 | +Object.assign(process.env, { |
| 10 | + RUNNER_TEMP: path.join(TEMP_DIR, 'runner_temp'), |
| 11 | + ACTIONS_RESULTS_URL: 'http://localhost:3000/', |
| 12 | + ACTIONS_CACHE_URL: 'http://localhost:3000/', |
| 13 | + ACTIONS_CACHE_SERVICE_V2: 'true', |
| 14 | + ACTIONS_RUNTIME_TOKEN: 'mock-runtime', |
| 15 | +}) |
| 16 | + |
| 17 | +const CONCURRENCY = 20 |
| 18 | +const FILE_SIZE_MB = 500 |
| 19 | +const TOTAL_REQUESTS = 10 |
| 20 | + |
| 21 | +const MOCK_BUFFER = randomBytes(1024 * 1024 * FILE_SIZE_MB) |
| 22 | + |
| 23 | +async function run(id: number) { |
| 24 | + const testFilePath = path.join(TEMP_DIR, `test-file-${id}.bin`) |
| 25 | + await fs.writeFile(testFilePath, MOCK_BUFFER) |
| 26 | + |
| 27 | + await saveCache([testFilePath], `key`) |
| 28 | + await restoreCache([testFilePath], `key`) |
| 29 | +} |
| 30 | + |
| 31 | +await fs.mkdir(TEMP_DIR, { recursive: true }) |
| 32 | + |
| 33 | +const limiter = pLimit(CONCURRENCY) |
| 34 | + |
| 35 | +const start = Date.now() |
| 36 | +await Promise.all(Array.from({ length: TOTAL_REQUESTS }, (_, i) => limiter(() => run(i)))) |
| 37 | +const duration = Date.now() - start |
| 38 | + |
| 39 | +console.log(`Completed ${TOTAL_REQUESTS} requests in ${duration}ms`) |
| 40 | + |
| 41 | +await fs.rm(TEMP_DIR, { recursive: true, force: true }) |
0 commit comments