Skip to content

Commit

Permalink
[Perf framework] Remove run method - cleaning up (#16391)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshaNalluru authored Jul 15, 2021
1 parent 8cce4c7 commit 712c0a6
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 66 deletions.
6 changes: 6 additions & 0 deletions sdk/test-utils/perfstress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

## 1.0.0 (Unreleased)

### 2021-07-14

- Removed the run method in the `PerfStressTest` class as we only deal with the async methods when it comes to performance.

### 2020-04-22

- Merged the first working implementation of perfstress.
5 changes: 0 additions & 5 deletions sdk/test-utils/perfstress/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export interface DefaultPerfStressOptions {
iterations: number;
"no-cleanup": boolean;
"milliseconds-to-log": number;
sync: boolean;
}

/**
Expand Down Expand Up @@ -96,10 +95,6 @@ export const defaultPerfStressOptions: PerfStressOptionDictionary<DefaultPerfStr
shortName: "i",
defaultValue: 1
},
sync: {
description: "Only runs the 'run' method instead of the 'runAsync' method",
defaultValue: false
},
"no-cleanup": {
description: "Disables test cleanup"
},
Expand Down
52 changes: 4 additions & 48 deletions sdk/test-utils/perfstress/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,6 @@ export class PerfStressProgram {
);
}

/**
* Runs the test in scope repeatedly, without waiting for any promises to finish,
* as many times as possible until durationMilliseconds is reached.
* For each test run, it will report one more completedOperations on the PerfStressParallel given,
* as well as the lastMillisecondsElapsed that reports the last test execution's elapsed time in comparison
* to the beginning of the execution of runLoop.
*
* @param parallel Object where to log the results from each execution.
* @param durationMilliseconds When to abort any execution.
* @param abortController Allows us to send through a signal determining when to abort any execution.
*/
private runLoopSync(
test: PerfStressTest,
parallel: PerfStressParallel,
durationMilliseconds: number,
abortController: AbortController
): void {
if (!test.run) {
throw new Error(`The "run" method is missing in the test ${this.testName}`);
}
const start = process.hrtime();
while (!abortController.signal.aborted) {
test.run(abortController.signal);

const elapsed = process.hrtime(start);
const elapsedMilliseconds = elapsed[0] * 1000 + elapsed[1] / 1000000;

parallel.completedOperations += 1;
parallel.lastMillisecondsElapsed = elapsedMilliseconds;

// In runTest we create a setTimeout that is intended to abort the abortSignal
// once the durationMilliseconds have elapsed. That setTimeout might not get queued
// on time through the event loop, depending on the number of operations we might be executing.
// For this reason, we're also manually checking the elapsed time here.
if (abortController.signal.aborted || elapsedMilliseconds > durationMilliseconds) {
abortController.abort();
break;
}
}
}

/**
* Runs the test in scope repeatedly, without waiting for any promises to finish,
* as many times as possible until durationMilliseconds is reached.
Expand Down Expand Up @@ -201,7 +160,7 @@ export class PerfStressProgram {
title: string
): Promise<void> {
const parallels: PerfStressParallel[] = new Array<PerfStressParallel>(this.parallelNumber);
const parallelTestResults: Promise<void>[] | void[] = new Array<void>(this.parallelNumber);
const parallelTestResults: Array<Promise<void>> = new Array<Promise<void>>(this.parallelNumber);

const abortController = new AbortController();
const durationMilliseconds = durationSeconds * 1000;
Expand Down Expand Up @@ -231,8 +190,7 @@ export class PerfStressProgram {
console.log(`${currentCompleted}\t\t${totalCompleted}\t\t${averageCompleted.toFixed(2)}`);
}, millisecondsToLog);

const isAsync = !this.parsedDefaultOptions.sync.value;
const runLoop = isAsync ? this.runLoopAsync : this.runLoopSync;
const runLoop = this.runLoopAsync;

// Unhandled exceptions should stop the whole PerfStress process.
process.on("unhandledRejection", (error) => {
Expand Down Expand Up @@ -260,10 +218,8 @@ export class PerfStressProgram {
);
}

if (isAsync) {
for (const promise of parallelTestResults) {
await promise;
}
for (const promise of parallelTestResults) {
await promise;
}

// Once we finish, we clear the log interval.
Expand Down
1 change: 0 additions & 1 deletion sdk/test-utils/perfstress/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export abstract class PerfStressTest<TOptions = {}> {
public setup?(): void | Promise<void>;
public cleanup?(): void | Promise<void>;

public run?(abortSignal?: AbortSignalLike): void;
public async runAsync?(abortSignal?: AbortSignalLike): Promise<void>;
}

Expand Down
8 changes: 0 additions & 8 deletions sdk/test-utils/perfstress/test/exception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import { PerfStressTest } from "../src";
export class Exception extends PerfStressTest {
public options = {};

run(): void {
try {
throw new Error();
} catch (e) {
// Nothing to do here
}
}

async runAsync(): Promise<void> {
try {
throw new Error();
Expand Down
2 changes: 0 additions & 2 deletions sdk/test-utils/perfstress/test/noop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ import { PerfStressTest } from "../src";
export class NoOp extends PerfStressTest {
public options = {};

run(): void {}

async runAsync(): Promise<void> {}
}
2 changes: 1 addition & 1 deletion sdk/test-utils/perfstress/test/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class OptionsTest extends PerfStressTest<OptionsTestOptions> {
}
}

run(): void {
async runAsync() {
for (const key in this.options) {
this.compare(key as keyof OptionsTestOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/perfstress/test/setupCleanup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export class SetupCleanupTest extends PerfStressTest {
}
}

run(): void {}
async runAsync() {}
}

0 comments on commit 712c0a6

Please sign in to comment.