mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(agent): benchmark session repository lifecycle
This commit is contained in:
parent
a2fd9783f5
commit
0bddd620d6
3 changed files with 74 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
SESSION_REPO_CATALOG_BENCHMARK_DATASETS,
|
||||
SESSION_REPO_CATALOG_READ_BENCHMARK_SCENARIOS,
|
||||
SESSION_REPO_CATALOG_WRITE_BENCHMARK_SCENARIOS,
|
||||
SESSION_REPO_FORK_BENCHMARK_DATASETS,
|
||||
SESSION_REPO_FORK_WRITE_BENCHMARK_SCENARIOS,
|
||||
seedSessionRepoCatalogBenchmark,
|
||||
|
|
@ -21,6 +22,20 @@ await registerReadBenchmarks({
|
|||
},
|
||||
});
|
||||
|
||||
await registerWriteBenchmarks({
|
||||
targets: sessionRepoBenchmarkTargets,
|
||||
scenarios: SESSION_REPO_CATALOG_WRITE_BENCHMARK_SCENARIOS,
|
||||
prepare(fixture, scenario) {
|
||||
return scenario.prepare(fixture.repo);
|
||||
},
|
||||
expectedResult(scenario) {
|
||||
return scenario.expectedResult;
|
||||
},
|
||||
run(operation) {
|
||||
return operation.run();
|
||||
},
|
||||
});
|
||||
|
||||
const forkBenchmarks = SESSION_REPO_FORK_BENCHMARK_DATASETS.flatMap((dataset) =>
|
||||
SESSION_REPO_FORK_WRITE_BENCHMARK_SCENARIOS.map((scenario) => ({
|
||||
name: `${scenario.name} (${dataset.name})`,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,16 @@ interface SessionRepoCatalogReadBenchmarkScenario {
|
|||
run(repo: SessionRepo): Promise<number>;
|
||||
}
|
||||
|
||||
interface SessionRepoCatalogWriteBenchmarkOperation {
|
||||
run(): Promise<number>;
|
||||
}
|
||||
|
||||
interface SessionRepoCatalogWriteBenchmarkScenario {
|
||||
readonly name: string;
|
||||
readonly expectedResult: number;
|
||||
prepare(repo: SessionRepo): Promise<SessionRepoCatalogWriteBenchmarkOperation>;
|
||||
}
|
||||
|
||||
interface SessionRepoForkWriteBenchmarkScenario {
|
||||
readonly name: string;
|
||||
expectedResult(dataset: StorageBenchmarkDataset): number;
|
||||
|
|
@ -24,7 +34,7 @@ export function sessionRepoBenchmarkSessionId(index: number): string {
|
|||
return `benchmark-session-${index.toString().padStart(8, "0")}`;
|
||||
}
|
||||
|
||||
const FORK_SOURCE_SESSION_ID = sessionRepoBenchmarkSessionId(0);
|
||||
const BENCHMARK_SESSION_ID = sessionRepoBenchmarkSessionId(0);
|
||||
const FORK_DESTINATION_SESSION_ID = sessionRepoBenchmarkSessionId(1);
|
||||
|
||||
function createCatalogDataset(scale: string, sessionCount: number): SessionRepoCatalogBenchmarkDataset {
|
||||
|
|
@ -68,6 +78,52 @@ export const SESSION_REPO_CATALOG_READ_BENCHMARK_SCENARIOS: readonly SessionRepo
|
|||
},
|
||||
];
|
||||
|
||||
/** Shared catalog writes. Every invocation receives an equivalent independently prepared repository. */
|
||||
export const SESSION_REPO_CATALOG_WRITE_BENCHMARK_SCENARIOS: readonly SessionRepoCatalogWriteBenchmarkScenario[] = [
|
||||
{
|
||||
name: "create empty session",
|
||||
expectedResult: 1,
|
||||
prepare(repo) {
|
||||
return Promise.resolve({
|
||||
async run() {
|
||||
const session = await repo.create({ id: BENCHMARK_SESSION_ID });
|
||||
return session.metadata.id === BENCHMARK_SESSION_ID ? 1 : 0;
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "open closed empty session",
|
||||
expectedResult: 1,
|
||||
async prepare(repo) {
|
||||
const session = await repo.create({ id: BENCHMARK_SESSION_ID });
|
||||
const { metadata } = session;
|
||||
await session.close();
|
||||
return {
|
||||
async run() {
|
||||
const reopened = await repo.open(metadata);
|
||||
return reopened.metadata.id === metadata.id ? 1 : 0;
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "delete closed empty session",
|
||||
expectedResult: 1,
|
||||
async prepare(repo) {
|
||||
const session = await repo.create({ id: BENCHMARK_SESSION_ID });
|
||||
const { metadata } = session;
|
||||
await session.close();
|
||||
return {
|
||||
async run() {
|
||||
await repo.delete(metadata);
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/** Initial fork timing uses a bounded source because each iteration owns an equivalent seeded repository. */
|
||||
export const SESSION_REPO_FORK_BENCHMARK_DATASETS: readonly StorageBenchmarkDataset[] = [
|
||||
STORAGE_BENCHMARK_DATASETS[0]!,
|
||||
|
|
@ -79,7 +135,7 @@ export async function seedSessionRepoForkBenchmark(
|
|||
repo: SessionRepo,
|
||||
dataset: StorageBenchmarkDataset,
|
||||
): Promise<SessionMetadata> {
|
||||
const session = await repo.create({ id: FORK_SOURCE_SESSION_ID });
|
||||
const session = await repo.create({ id: BENCHMARK_SESSION_ID });
|
||||
for (const transaction of generateStorageBenchmarkSeedTransactions(dataset)) {
|
||||
await session.mutate("main", (mutator) => mutator.commit(transaction));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ export { STORAGE_BENCHMARK_DATASETS } from "./benchmark/datasets.ts";
|
|||
export {
|
||||
SESSION_REPO_CATALOG_BENCHMARK_DATASETS,
|
||||
SESSION_REPO_CATALOG_READ_BENCHMARK_SCENARIOS,
|
||||
SESSION_REPO_CATALOG_WRITE_BENCHMARK_SCENARIOS,
|
||||
SESSION_REPO_FORK_BENCHMARK_DATASETS,
|
||||
SESSION_REPO_FORK_WRITE_BENCHMARK_SCENARIOS,
|
||||
type SessionRepoCatalogBenchmarkDataset,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue