Skip to content

chore(NODE-6871): make tags required and add tags to composite scores #4480

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

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions test/benchmarks/driver_bench/src/driver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ const __dirname = import.meta.dirname;
const require = module.createRequire(__dirname);

export const TAG = {
// Special tag that marks a benchmark as a spec-required benchmark
/** Special tag that marks a benchmark as a spec-required benchmark */
spec: 'spec-benchmark',
// Special tag that enables our perf monitoring tooling to create alerts when regressions in this
// benchmark's performance are detected
/** Special tag that enables our perf monitoring tooling to create alerts when regressions in this benchmark's performance are detected */
alert: 'alerting-benchmark',
// Tag marking a benchmark as being related to cursor performance
/** Tag marking a benchmark as being related to cursor performance */
cursor: 'cursor-benchmark',
// Tag marking a benchmark as being related to read performance
/** Tag marking a benchmark as being related to read performance */
read: 'read-benchmark',
// Tag marking a benchmark as being related to write performance
write: 'write-benchmark'
/** Tag marking a benchmark as being related to write performance */
write: 'write-benchmark',
/** A tag for the cpu baseline task */
reference: 'reference'
};

/**
Expand Down Expand Up @@ -135,7 +136,7 @@ export type Metric = {
name: 'megabytes_per_second' | 'normalized_throughput';
value: number;
metadata: {
tags?: string[];
tags: ReadonlyArray<string>;
improvement_direction: 'up' | 'down';
};
};
Expand All @@ -150,7 +151,11 @@ export type MetricInfo = {
metrics: Metric[];
};

export function metrics(test_name: string, result: number, tags?: string[]): MetricInfo {
export function metrics(
test_name: string,
result: number,
tags: ReadonlyArray<string>
): MetricInfo {
return {
info: {
test_name,
Expand Down
7 changes: 4 additions & 3 deletions test/benchmarks/driver_bench/src/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
MONGODB_DRIVER_PATH,
MONGODB_DRIVER_REVISION,
MONGODB_DRIVER_VERSION,
snakeToCamel
snakeToCamel,
TAG
} from './driver.mjs';

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

compositeResults.push(metrics(compositeName, compositeAverage));
compositeResults.push(metrics(compositeName, compositeAverage, [TAG.spec]));

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

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

compositeResults.push(metrics('driverBench', driverBench));
compositeResults.push(metrics('driverBench', driverBench, [TAG.spec]));

console.groupEnd();
return [...results, ...compositeResults];
Expand Down
17 changes: 7 additions & 10 deletions test/benchmarks/driver_bench/src/runner.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ const [, , benchmarkFile] = process.argv;

type BenchmarkModule = {
taskSize: number;
tags: ReadonlyArray<string>;

before?: () => Promise<void>;
beforeEach?: () => Promise<void>;
run: () => Promise<void>;
afterEach?: () => Promise<void>;
after?: () => Promise<void>;
tags?: string[];
};

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

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

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

const tags = benchmark.tags;
if (
tags &&
(!Array.isArray(tags) || (tags.length > 0 && !tags.every(t => typeof t === 'string')))
) {
throw new Error('If tags is specified, it MUST be an array of strings');
}

console.log(
' '.repeat(3),
...['total time:', totalDuration, 'sec,'],
Expand All @@ -100,6 +97,6 @@ console.log(

await fs.writeFile(
`results_${path.basename(benchmarkFile, '.mjs')}.json`,
JSON.stringify(metrics(benchmarkName, megabytesPerSecond, tags), undefined, 2) + '\n',
JSON.stringify(metrics(benchmarkName, megabytesPerSecond, benchmark.tags), undefined, 2) + '\n',
'utf8'
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import assert from 'node:assert/strict';

import { TAG } from '../../driver.mjs';

const findPrimesBelow = 1_000_000;
const expectedPrimes = 78_498;

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

const stableRegionMean = 42.82;
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

export const tags = [TAG.reference];

/** @see https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes */
export function sieveOfEratosthenes(n: number) {
// Create a boolean array "prime[0..n]" and initialize
Expand Down