-
Notifications
You must be signed in to change notification settings - Fork 55
feat: add storage concurrency benchmark #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kisernl
wants to merge
7
commits into
master
Choose a base branch
from
storage-concurrency-bench
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e01fd5e
feat: add storage concurrency benchmark
kisernl c861b02
feat: add storage corpus seeding and smoke controls
kisernl 0ef6f47
feat: collect storage concurrency comparisons
kisernl e350725
feat: add storage concurrency composite score
kisernl 3915558
feat: show provider ranking in action summary
kisernl 33f1142
fix: distribute single-prefix corpus keys
kisernl 6d64170
fix: skip providers with invalid credentials
kisernl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { normalizeGcsPrivateKey } from './providers.js'; | ||
|
|
||
| const pemBody = 'abc\\ndef'; | ||
| assert.equal(normalizeGcsPrivateKey(pemBody), 'abc\ndef'); | ||
| assert.equal(normalizeGcsPrivateKey(JSON.stringify(pemBody)), 'abc\ndef'); | ||
| assert.equal(normalizeGcsPrivateKey('abc\r\ndef'), 'abc\ndef'); | ||
|
|
||
| console.log('Storage provider credential normalization checks passed'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { | ||
| STORAGE_CONCURRENCY_RESULTS_PATH, | ||
| type StorageConcurrencyResults, | ||
| } from './storage-concurrency-results.js'; | ||
|
|
||
| const root = path.resolve('.'); | ||
| const input = process.env.STORAGE_CONCURRENCY_RESULTS | ||
| ? path.resolve(process.env.STORAGE_CONCURRENCY_RESULTS) | ||
| : STORAGE_CONCURRENCY_RESULTS_PATH; | ||
| const data = JSON.parse(fs.readFileSync(input, 'utf8')) as StorageConcurrencyResults; | ||
|
|
||
| function providerName(provider: string): string { | ||
| return { | ||
| 'aws-s3': 'AWS S3', | ||
| 'cloudflare-r2': 'Cloudflare R2', | ||
| 'vercel-blob': 'Vercel Blob', | ||
| 'azure-blob': 'Azure Blob', | ||
| }[provider] ?? provider; | ||
| } | ||
|
|
||
| function number(value: number | null): string { | ||
| return value === null ? '—' : value.toFixed(1); | ||
| } | ||
|
|
||
| function escapeXml(value: string): string { | ||
| return value.replace(/[<>&"']/g, (character) => ({ | ||
| '<': '<', | ||
| '>': '>', | ||
| '&': '&', | ||
| '"': '"', | ||
| "'": ''', | ||
| }[character]!)); | ||
| } | ||
|
|
||
| const rows = data.results.flatMap((provider) => | ||
| provider.cells.map((cell) => ({ | ||
| provider: providerName(provider.provider), | ||
| ...cell, | ||
| })), | ||
| ); | ||
|
|
||
| const summaries = [...data.results] | ||
| .sort((a, b) => b.compositeScore - a.compositeScore) | ||
| .map((provider) => ({ | ||
| ...provider, | ||
| displayName: providerName(provider.provider), | ||
| peakThroughput: Math.max(...provider.cells.map((cell) => cell.throughputOpsPerSecond), 0), | ||
| })); | ||
|
|
||
| const markdown = [ | ||
| '# Storage Concurrency Results', | ||
| '', | ||
| `Run: \`${data.runId}\` `, | ||
| `Generated: ${data.timestamp}`, | ||
| '', | ||
| '## Provider ranking', | ||
| '', | ||
| ...(summaries.length > 0 | ||
| ? [`Top provider: **${summaries[0].displayName}** (${summaries[0].compositeScore.toFixed(2)}/100)`, ''] | ||
| : ['No provider results were available.', '']), | ||
| '| Rank | Provider | Composite score | Success rate | Valid cells | Peak throughput (ops/s) |', | ||
| '|---:|---|---:|---:|---:|---:|', | ||
| ...summaries.map((provider, index) => | ||
| `| ${index + 1} | ${provider.displayName} | ${provider.compositeScore.toFixed(2)} | ${(provider.successRate * 100).toFixed(1)}% | ${(provider.validCellRate * 100).toFixed(1)}% | ${provider.peakThroughput.toFixed(1)} |`, | ||
| ), | ||
| '', | ||
| 'Scores combine throughput (45%), p50 latency (20%), p95 latency (20%), and p99 latency (15%) per cell, then apply success-rate penalties.', | ||
| '', | ||
| '## Cell details', | ||
| '', | ||
| '| Provider | Cell | Throughput (ops/s) | p50 (ms) | p95 (ms) | p99 (ms) | Success | Valid |', | ||
| '|---|---|---:|---:|---:|---:|---:|:---:|', | ||
| ...rows.map((row) => | ||
| `| ${row.provider} | ${row.phase} | ${row.throughputOpsPerSecond.toFixed(1)} | ${number(row.p50Ms)} | ${number(row.p95Ms)} | ${number(row.p99Ms)} | ${(row.successRate * 100).toFixed(1)}% | ${row.valid ? 'yes' : 'NO'} |`, | ||
| ), | ||
| '', | ||
| 'This is a closed-loop benchmark. Throughput is the output observed at the requested client concurrency.', | ||
| ].join('\n'); | ||
|
|
||
| fs.writeFileSync(path.join(root, 'storage-concurrency.md'), `${markdown}\n`); | ||
|
|
||
| const width = 1200; | ||
| const rowHeight = 28; | ||
| const headerHeight = 70; | ||
| const chartHeight = Math.max(180, summaries.length * rowHeight + 90); | ||
| const barWidth = 700; | ||
| const chartRows = summaries.map((row, index) => { | ||
| const y = headerHeight + index * rowHeight; | ||
| const widthValue = Math.max(1, (row.compositeScore / 100) * barWidth); | ||
| return ` | ||
| <text x="12" y="${y + 18}" class="label">${escapeXml(row.displayName)}</text> | ||
| <rect x="390" y="${y + 4}" width="${widthValue.toFixed(1)}" height="18" class="${row.validCellRate === 1 ? 'bar' : 'invalid'}"/> | ||
| <text x="${Math.min(1100, 400 + widthValue + 8)}" y="${y + 18}" class="value">${row.compositeScore.toFixed(2)}</text>`; | ||
| }).join(''); | ||
|
|
||
| const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${chartHeight}" viewBox="0 0 ${width} ${chartHeight}"> | ||
| <style> | ||
| .title { font: 700 24px sans-serif; fill: #24292f; } | ||
| .subtitle { font: 13px sans-serif; fill: #57606a; } | ||
| .label { font: 12px sans-serif; fill: #24292f; } | ||
| .value { font: 12px sans-serif; fill: #57606a; } | ||
| .bar { fill: #0969da; } | ||
| .invalid { fill: #cf222e; } | ||
| </style> | ||
| <rect width="100%" height="100%" fill="white"/> | ||
| <text x="12" y="30" class="title">Storage Concurrency Composite Score</text> | ||
| <text x="12" y="50" class="subtitle">Run ${escapeXml(data.runId)} · higher is better</text> | ||
| ${chartRows} | ||
| </svg>`; | ||
|
|
||
| fs.writeFileSync(path.join(root, 'storage-concurrency.svg'), svg); | ||
| console.log('Wrote storage-concurrency.md and storage-concurrency.svg'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { requestKey } from './storage-concurrency-corpus.js'; | ||
|
|
||
| function prefix(key: string): string { | ||
| return key.split('/')[2]!; | ||
| } | ||
|
|
||
| const workerZeroKeys = Array.from( | ||
| { length: 32 }, | ||
| (_, opSeq) => requestKey(0, opSeq, 'SINGLE_PREFIX'), | ||
| ); | ||
| const workerOneKeys = Array.from( | ||
| { length: 32 }, | ||
| (_, opSeq) => requestKey(1, opSeq, 'SINGLE_PREFIX'), | ||
| ); | ||
|
|
||
| assert.ok(workerZeroKeys.every((key) => prefix(key) === 'p00')); | ||
| assert.ok(workerOneKeys.every((key) => prefix(key) === 'p00')); | ||
| assert.notDeepEqual(workerZeroKeys, workerOneKeys); | ||
|
|
||
| const singlePrefixKeys = new Set( | ||
| Array.from({ length: 128 }, (_, workerId) => | ||
| requestKey(workerId, 0, 'SINGLE_PREFIX'), | ||
| ), | ||
| ); | ||
| assert.equal(singlePrefixKeys.size, 128); | ||
|
|
||
| console.log('Storage concurrency corpus key distribution checks passed'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| export const OBJECT_COUNT = 10_000; | ||
| export const PREFIX_COUNT = 64; | ||
| export const OBJECT_SIZE_BYTES = 1024; | ||
| export const KEY_STRIDE = 7919; | ||
| export const WORKER_PRIME = 104_729; | ||
| const SINGLE_PREFIX_OBJECT_COUNT = Math.ceil(OBJECT_COUNT / PREFIX_COUNT); | ||
|
|
||
| export type KeyDistribution = 'SINGLE_PREFIX' | 'SPREAD_64'; | ||
|
|
||
| export function corpusKey(index: number): string { | ||
| if (!Number.isInteger(index) || index < 0 || index >= OBJECT_COUNT) { | ||
| throw new Error(`Corpus index must be between 0 and ${OBJECT_COUNT - 1}`); | ||
| } | ||
| const prefix = index % PREFIX_COUNT; | ||
| return `bench/v1/p${prefix.toString().padStart(2, '0')}/obj${index.toString().padStart(6, '0')}`; | ||
| } | ||
|
|
||
| export function requestKey( | ||
| workerId: number, | ||
| opSeq: number, | ||
| distribution: KeyDistribution, | ||
| ): string { | ||
| const rawIndex = distribution === 'SINGLE_PREFIX' | ||
| ? (workerId * WORKER_PRIME + opSeq * KEY_STRIDE) % SINGLE_PREFIX_OBJECT_COUNT | ||
| : (workerId * WORKER_PRIME + opSeq * KEY_STRIDE) % OBJECT_COUNT; | ||
| const index = distribution === 'SINGLE_PREFIX' ? rawIndex * PREFIX_COUNT : rawIndex; | ||
| return corpusKey(index); | ||
| } | ||
|
|
||
| /** Stable 1 KB body shared by every seeded object. */ | ||
| export function corpusBody(): Uint8Array { | ||
| return Uint8Array.from( | ||
| { length: OBJECT_SIZE_BYTES }, | ||
| (_, index) => (index * 31 + 17) % 256, | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import type { BenchmarkRunOutcome } from '@benchsdk/runner'; | ||
| import { scoreStorageConcurrencyProvider } from './storage-concurrency-scoring.js'; | ||
|
|
||
| export const STORAGE_CONCURRENCY_RESULTS_DIR = path.resolve('results/storage-concurrency'); | ||
| export const STORAGE_CONCURRENCY_RESULTS_PATH = path.join( | ||
| STORAGE_CONCURRENCY_RESULTS_DIR, | ||
| 'latest.json', | ||
| ); | ||
|
|
||
| export interface StorageConcurrencyCellResult { | ||
| phase: string; | ||
| operations: number; | ||
| measuredOperations: number; | ||
| concurrency: number; | ||
| keyDistribution: 'SINGLE_PREFIX' | 'SPREAD_64'; | ||
| throughputOpsPerSecond: number; | ||
| p50Ms: number | null; | ||
| p95Ms: number | null; | ||
| p99Ms: number | null; | ||
| successRate: number; | ||
| throttleRate: number; | ||
| timeoutRate: number; | ||
| connectionErrorRate: number; | ||
| notFoundRate: number; | ||
| serverErrorRate: number; | ||
| clientErrorRate: number; | ||
| valid: boolean; | ||
| maxActiveRequests: number; | ||
| } | ||
|
|
||
| export interface StorageConcurrencyProviderResult { | ||
| provider: string; | ||
| cells: StorageConcurrencyCellResult[]; | ||
| compositeScore: number; | ||
| successRate: number; | ||
| validCellRate: number; | ||
| } | ||
|
|
||
| export interface StorageConcurrencyResults { | ||
| version: '1.0'; | ||
| timestamp: string; | ||
| runId: string; | ||
| environment: { | ||
| node: string; | ||
| platform: string; | ||
| arch: string; | ||
| }; | ||
| results: StorageConcurrencyProviderResult[]; | ||
| } | ||
|
|
||
| function isCellResult(value: unknown): value is StorageConcurrencyCellResult { | ||
| return typeof value === 'object' && value !== null | ||
| && typeof (value as { phase?: unknown }).phase === 'string' | ||
| && typeof (value as { concurrency?: unknown }).concurrency === 'number' | ||
| && typeof (value as { throughputOpsPerSecond?: unknown }).throughputOpsPerSecond === 'number'; | ||
| } | ||
|
|
||
| export function writeStorageConcurrencyResults( | ||
| outcome: BenchmarkRunOutcome, | ||
| ): void { | ||
| const results: StorageConcurrencyProviderResult[] = outcome.participants.map((participant) => { | ||
| const result = { | ||
| provider: participant.participant, | ||
| cells: participant.records.flatMap((record) => { | ||
| const data = record.data; | ||
| return isCellResult(data) ? [data] : []; | ||
| }), | ||
| }; | ||
| return { ...result, ...scoreStorageConcurrencyProvider(result) }; | ||
| }); | ||
|
|
||
| const output: StorageConcurrencyResults = { | ||
| version: '1.0', | ||
| timestamp: new Date().toISOString(), | ||
| runId: outcome.runId, | ||
| environment: { | ||
| node: process.version, | ||
| platform: os.platform(), | ||
| arch: os.arch(), | ||
| }, | ||
| results, | ||
| }; | ||
|
|
||
| fs.mkdirSync(STORAGE_CONCURRENCY_RESULTS_DIR, { recursive: true }); | ||
| fs.writeFileSync(STORAGE_CONCURRENCY_RESULTS_PATH, `${JSON.stringify(output, null, 2)}\n`); | ||
| console.log(`Storage concurrency results written to ${STORAGE_CONCURRENCY_RESULTS_PATH}`); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.