Skip to content

Commit 892c14d

Browse files
authored
chore(NODE-6871): make tags required and add tags to composite scores (#4480)
1 parent 20f7db7 commit 892c14d

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

test/benchmarks/driver_bench/src/driver.mts

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ const __dirname = import.meta.dirname;
88
const require = module.createRequire(__dirname);
99

1010
export const TAG = {
11-
// Special tag that marks a benchmark as a spec-required benchmark
11+
/** Special tag that marks a benchmark as a spec-required benchmark */
1212
spec: 'spec-benchmark',
13-
// Special tag that enables our perf monitoring tooling to create alerts when regressions in this
14-
// benchmark's performance are detected
13+
/** Special tag that enables our perf monitoring tooling to create alerts when regressions in this benchmark's performance are detected */
1514
alert: 'alerting-benchmark',
16-
// Tag marking a benchmark as being related to cursor performance
15+
/** Tag marking a benchmark as being related to cursor performance */
1716
cursor: 'cursor-benchmark',
18-
// Tag marking a benchmark as being related to read performance
17+
/** Tag marking a benchmark as being related to read performance */
1918
read: 'read-benchmark',
20-
// Tag marking a benchmark as being related to write performance
21-
write: 'write-benchmark'
19+
/** Tag marking a benchmark as being related to write performance */
20+
write: 'write-benchmark',
21+
/** A tag for the cpu baseline task */
22+
reference: 'reference'
2223
};
2324

2425
/**
@@ -135,7 +136,7 @@ export type Metric = {
135136
name: 'megabytes_per_second' | 'normalized_throughput';
136137
value: number;
137138
metadata: {
138-
tags?: string[];
139+
tags: ReadonlyArray<string>;
139140
improvement_direction: 'up' | 'down';
140141
};
141142
};
@@ -150,7 +151,11 @@ export type MetricInfo = {
150151
metrics: Metric[];
151152
};
152153

153-
export function metrics(test_name: string, result: number, tags?: string[]): MetricInfo {
154+
export function metrics(
155+
test_name: string,
156+
result: number,
157+
tags: ReadonlyArray<string>
158+
): MetricInfo {
154159
return {
155160
info: {
156161
test_name,

test/benchmarks/driver_bench/src/main.mts

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
MONGODB_DRIVER_PATH,
1919
MONGODB_DRIVER_REVISION,
2020
MONGODB_DRIVER_VERSION,
21-
snakeToCamel
21+
snakeToCamel,
22+
TAG
2223
} from './driver.mjs';
2324

2425
const __dirname = import.meta.dirname;
@@ -176,7 +177,7 @@ function calculateCompositeBenchmarks(results: MetricInfo[]) {
176177
if (compositeName === 'readBench') readBenchResult = compositeAverage;
177178
if (compositeName === 'writeBench') writeBenchResult = compositeAverage;
178179

179-
compositeResults.push(metrics(compositeName, compositeAverage));
180+
compositeResults.push(metrics(compositeName, compositeAverage, [TAG.spec]));
180181

181182
console.log('avg:', compositeAverage, 'mb/s');
182183

@@ -192,7 +193,7 @@ function calculateCompositeBenchmarks(results: MetricInfo[]) {
192193
console.log('avg:', driverBench, 'mb/s');
193194
console.groupEnd();
194195

195-
compositeResults.push(metrics('driverBench', driverBench));
196+
compositeResults.push(metrics('driverBench', driverBench, [TAG.spec]));
196197

197198
console.groupEnd();
198199
return [...results, ...compositeResults];

test/benchmarks/driver_bench/src/runner.mts

+7-10
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ const [, , benchmarkFile] = process.argv;
99

1010
type BenchmarkModule = {
1111
taskSize: number;
12+
tags: ReadonlyArray<string>;
13+
1214
before?: () => Promise<void>;
1315
beforeEach?: () => Promise<void>;
1416
run: () => Promise<void>;
1517
afterEach?: () => Promise<void>;
1618
after?: () => Promise<void>;
17-
tags?: string[];
1819
};
1920

2021
const benchmarkName = snakeToCamel(path.basename(benchmarkFile, '.mjs'));
2122
const benchmark: BenchmarkModule = await import(`./${benchmarkFile}`);
2223

2324
if (typeof benchmark.taskSize !== 'number') throw new Error('missing taskSize');
2425
if (typeof benchmark.run !== 'function') throw new Error('missing run');
26+
if (!Array.isArray(benchmark.tags)) throw new Error('tags must be an array');
27+
if (benchmark.tags.length === 0 || !benchmark.tags.every(t => typeof t === 'string')) {
28+
throw new Error('must have more than one tag and all tags must be strings');
29+
}
2530

2631
/** CRITICAL SECTION: time task took in seconds */
2732
async function timeTask() {
@@ -81,14 +86,6 @@ function percentileIndex(percentile: number, count: number) {
8186
const medianExecution = durations[percentileIndex(50, count)];
8287
const megabytesPerSecond = benchmark.taskSize / medianExecution;
8388

84-
const tags = benchmark.tags;
85-
if (
86-
tags &&
87-
(!Array.isArray(tags) || (tags.length > 0 && !tags.every(t => typeof t === 'string')))
88-
) {
89-
throw new Error('If tags is specified, it MUST be an array of strings');
90-
}
91-
9289
console.log(
9390
' '.repeat(3),
9491
...['total time:', totalDuration, 'sec,'],
@@ -100,6 +97,6 @@ console.log(
10097

10198
await fs.writeFile(
10299
`results_${path.basename(benchmarkFile, '.mjs')}.json`,
103-
JSON.stringify(metrics(benchmarkName, megabytesPerSecond, tags), undefined, 2) + '\n',
100+
JSON.stringify(metrics(benchmarkName, megabytesPerSecond, benchmark.tags), undefined, 2) + '\n',
104101
'utf8'
105102
);

test/benchmarks/driver_bench/src/suites/node_specific/cpu_baseline.mts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import assert from 'node:assert/strict';
22

3+
import { TAG } from '../../driver.mjs';
4+
35
const findPrimesBelow = 1_000_000;
46
const expectedPrimes = 78_498;
57

@@ -9,6 +11,9 @@ const expectedPrimes = 78_498;
911

1012
const stableRegionMean = 42.82;
1113
export const taskSize = 3.1401000000000003 / stableRegionMean; // ~3MB worth of work scaled down by the mean of the current stable region in CI to bring this value to roughly 1
14+
15+
export const tags = [TAG.reference];
16+
1217
/** @see https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes */
1318
export function sieveOfEratosthenes(n: number) {
1419
// Create a boolean array "prime[0..n]" and initialize

0 commit comments

Comments
 (0)