Skip to content

Commit

Permalink
Record and playback all test instances
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeharder committed Sep 22, 2021
1 parent 7a977fb commit 0121abf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
38 changes: 23 additions & 15 deletions sdk/test-utils/perfstress/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ export class PerfStressProgram {
`Completed ${totalOperations.toLocaleString(undefined, {
maximumFractionDigits: 0
})} ` +
`operations in a weighted-average of ` +
`${weightedAverage.toLocaleString(undefined, {
maximumFractionDigits: 2,
minimumFractionDigits: 2
})}s ` +
`(${operationsPerSecond.toLocaleString(undefined, {
maximumFractionDigits: 2
})} ops/s, ` +
`${secondsPerOperation.toLocaleString(undefined, {
maximumFractionDigits: 3,
minimumFractionDigits: 3
})} s/op)`
`operations in a weighted-average of ` +
`${weightedAverage.toLocaleString(undefined, {
maximumFractionDigits: 2,
minimumFractionDigits: 2
})}s ` +
`(${operationsPerSecond.toLocaleString(undefined, {
maximumFractionDigits: 2
})} ops/s, ` +
`${secondsPerOperation.toLocaleString(undefined, {
maximumFractionDigits: 3,
minimumFractionDigits: 3
})} s/op)`
);
}

Expand Down Expand Up @@ -186,7 +186,7 @@ export class PerfStressProgram {
const millisecondsToLog = Number(this.parsedDefaultOptions["milliseconds-to-log"].value);
console.log(
`\n=== ${title} mode, iteration ${iterationIndex + 1}. Logs every ${millisecondsToLog /
1000}s ===`
1000}s ===`
);
console.log(`Current\t\tTotal\t\tAverage`);
let lastCompleted = 0;
Expand Down Expand Up @@ -287,7 +287,7 @@ export class PerfStressProgram {
}

if (this.tests[0].parsedOptions["test-proxy"].value) {
await this.recordAndStartPlayback(this.tests[0]);
await this.recordAndStartPlaybacks(this.tests);
}

if (Number(options.warmup.value) > 0) {
Expand All @@ -300,7 +300,7 @@ export class PerfStressProgram {
}

if (this.tests[0].parsedOptions["test-proxy"].value) {
await this.stopPlayback(this.tests[0]);
await this.stopPlaybacks(this.tests);
}

if (!options["no-cleanup"].value && this.tests[0].cleanup) {
Expand All @@ -322,6 +322,10 @@ export class PerfStressProgram {
}
}

private async recordAndStartPlaybacks(tests: PerfStressTest[]) {
await Promise.all(tests.map(test => this.recordAndStartPlayback(test)));
}

/**
* This method records the requests-responses and lets the proxy-server know when to playback.
* We run runAsync once in record mode to save the requests and responses in memory and then a ton of times in playback.
Expand Down Expand Up @@ -373,6 +377,10 @@ export class PerfStressProgram {
recorder._mode = "playback";
}

private async stopPlaybacks(tests: PerfStressTest[]) {
await Promise.all(tests.map(test => this.stopPlayback(test)));
}

private async stopPlayback(test: PerfStressTest) {
if (test.testProxyHttpClient) {
await test.testProxyHttpClient.stopPlayback();
Expand Down
18 changes: 2 additions & 16 deletions sdk/test-utils/perfstress/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,10 @@ export async function makeRequest(
});
}

const _cachedProxyClients: {
v1: TestProxyHttpClientV1 | undefined;
v2: TestProxyHttpClient | undefined;
} = {
v1: undefined,
v2: undefined
};

export function getHttpClientV1(url: string): TestProxyHttpClientV1 {
if (!_cachedProxyClients.v1) {
_cachedProxyClients.v1 = new TestProxyHttpClientV1(url);
}
return _cachedProxyClients.v1;
return new TestProxyHttpClientV1(url);
}

export function getHttpClient(url: string): TestProxyHttpClient {
if (!_cachedProxyClients.v2) {
_cachedProxyClients.v2 = new TestProxyHttpClient(url);
}
return _cachedProxyClients.v2;
return new TestProxyHttpClient(url);
}

0 comments on commit 0121abf

Please sign in to comment.