Skip to content
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

ci(NODE-6755): add tags to benchmarks #4419

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 11 additions & 3 deletions test/benchmarks/driver_bench/src/driver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import process from 'node:process';
const __dirname = import.meta.dirname;
const require = module.createRequire(__dirname);

export const SPEC_TAG = 'spec-benchmark';
export const ALERT_TAG = 'alerting-benchmark';
export const CURSOR_TAG = 'cursor-benchmark';
export const READ_TAG = 'read-benchmark';
export const WRITE_TAG = 'write-benchmark';

/**
* The path to the MongoDB Node.js driver.
* This MUST be set to the directory the driver is installed in
Expand Down Expand Up @@ -118,19 +124,20 @@ export const PARALLEL_DIRECTORY = path.resolve(SPEC_DIRECTORY, 'parallel');
export const TEMP_DIRECTORY = path.resolve(SPEC_DIRECTORY, 'tmp');

export type Metric = {
name: 'megabytes_per_second';
name: 'megabytes_per_second' | 'normalized_throughput';
value: number;
};

export type MetricInfo = {
info: {
test_name: string;
args: Record<string, number>;
tags?: string[]
};
metrics: Metric[];
};

export function metrics(test_name: string, result: number): MetricInfo {
export function metrics(test_name: string, result: number, tags?: string[]): MetricInfo {
return {
info: {
test_name,
Expand All @@ -141,7 +148,8 @@ export function metrics(test_name: string, result: number): MetricInfo {
key,
typeof value === 'number' ? value : value ? 1 : 0
])
)
),
tags
},
metrics: [{ name: 'megabytes_per_second', value: result }]
} as const;
Expand Down
47 changes: 42 additions & 5 deletions test/benchmarks/driver_bench/src/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ console.log(systemInfo());

const runnerPath = path.join(__dirname, 'runner.mjs');

const results: MetricInfo[] = [];
let results: MetricInfo[] = [];

for (const [suite, benchmarks] of Object.entries(tests)) {
console.group(snakeToCamel(suite));
Expand Down Expand Up @@ -146,8 +146,8 @@ function calculateCompositeBenchmarks(results: MetricInfo[]) {

const aMetricInfo =
(testName: string) =>
({ info: { test_name } }: MetricInfo) =>
test_name === testName;
({ info: { test_name } }: MetricInfo) =>
test_name === testName;

const anMBsMetric = ({ name }: Metric) => name === 'megabytes_per_second';

Expand Down Expand Up @@ -198,6 +198,43 @@ function calculateCompositeBenchmarks(results: MetricInfo[]) {
return [...results, ...compositeResults];
}

const finalResults = calculateCompositeBenchmarks(results);
function calculateNormalizedResults(results: MetricInfo[]): MetricInfo[] {
const primesBench = results.find(r => r.info.test_name === 'primes');
const pingBench = results.find(r => r.info.test_name === 'ping');

if (pingBench) {
const newMetrics: MetricInfo[] = [];
const pingThroughput = pingBench.metrics[0].value;
for (const bench of results) {
if (bench.info.test_name === 'primes') {
newMetrics.push({ ...bench });
}
else if (bench.info.test_name === 'ping') {
// Compute ping's normalized_throughput against the primes bench if present
if (primesBench) {
const primesThroughput = primesBench.metrics[0].value;
const normalizedThroughput: Metric = { 'name': 'normalized_throughput', value: bench.metrics[0].value / primesThroughput };
const newInfo: MetricInfo = { info: { ...bench.info }, metrics: [...bench.metrics, normalizedThroughput] };
newMetrics.push(newInfo);
} else {
newMetrics.push({ ...bench });
}
} else {
// Compute normalized_throughput of benchmarks against ping bench
const normalizedThroughput: Metric = { 'name': 'normalized_throughput', value: bench.metrics[0].value / pingThroughput };
const newInfo: MetricInfo = { info: { ...bench.info }, metrics: [...bench.metrics, normalizedThroughput] }
newMetrics.push(newInfo);
}
}

return newMetrics;
}

return results;
}

results = calculateNormalizedResults(results);
results = calculateCompositeBenchmarks(results);


await fs.writeFile('results.json', JSON.stringify(finalResults, undefined, 2), 'utf8');
await fs.writeFile('results.json', JSON.stringify(results, undefined, 2), 'utf8');
5 changes: 4 additions & 1 deletion test/benchmarks/driver_bench/src/runner.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ type BenchmarkModule = {
run: () => Promise<void>;
afterEach?: () => Promise<void>;
after?: () => Promise<void>;
tags?: string[];
};


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

Expand Down Expand Up @@ -79,6 +81,7 @@ function percentileIndex(percentile: number, count: number) {

const medianExecution = durations[percentileIndex(50, count)];
const megabytesPerSecond = benchmark.taskSize / medianExecution;
const tags = benchmark.tags;

console.log(
' '.repeat(3),
Expand All @@ -91,6 +94,6 @@ console.log(

await fs.writeFile(
`results_${path.basename(benchmarkFile, '.mjs')}.json`,
JSON.stringify(metrics(benchmarkName, megabytesPerSecond), undefined, 2) + '\n',
JSON.stringify(metrics(benchmarkName, megabytesPerSecond, tags), undefined, 2) + '\n',
'utf8'
);
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { driver, type mongodb } from '../../driver.mjs';
import { driver, ALERT_TAG, SPEC_TAG, type mongodb, CURSOR_TAG, READ_TAG } from '../../driver.mjs';

export const taskSize = 16.22;

export const tags = [ALERT_TAG, SPEC_TAG, CURSOR_TAG, READ_TAG];

let collection: mongodb.Collection;

export async function before() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Readable, Writable } from 'node:stream';
import { pipeline } from 'node:stream/promises';

import { driver, type mongodb } from '../../driver.mjs';
import { driver, SPEC_TAG, ALERT_TAG, type mongodb, CURSOR_TAG, READ_TAG } from '../../driver.mjs';

export const taskSize = 52.43;

export const tags = [ALERT_TAG, SPEC_TAG, CURSOR_TAG, READ_TAG];

let bucket: mongodb.GridFSBucket;
let bin: Uint8Array;
let _id: mongodb.ObjectId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';

import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, SPEC_TAG, WRITE_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 52.43;
export const tags = [ALERT_TAG, SPEC_TAG, WRITE_TAG];

let bucket: mongodb.GridFSBucket;
let uploadStream: mongodb.GridFSBucketWriteStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, SPEC_TAG, WRITE_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 27.31;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

let collection: mongodb.Collection;
let documents: any[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, SPEC_TAG, WRITE_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 2.75;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

let collection: mongodb.Collection;
let documents: any[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, READ_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 16;
export const tags = [ALERT_TAG, READ_TAG];

let db: mongodb.Db;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, READ_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 1500;
export const tags = [ALERT_TAG, READ_TAG];

let db: mongodb.Db;
let tweet: Record<string, any>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, READ_TAG, SPEC_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 16.22;

export const tags = [SPEC_TAG, ALERT_TAG,READ_TAG]

let collection: mongodb.Collection;

export async function before() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, WRITE_TAG, type mongodb } from '../../driver.mjs';

// { ping: 1 } is 15 bytes of BSON x 10,000 iterations
export const taskSize = 0.15;
export const tags = [ALERT_TAG];

let db: mongodb.Db;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { createReadStream, createWriteStream, promises as fs } from 'node:fs';
import path from 'node:path';
import { pipeline } from 'node:stream/promises';

import { driver, type mongodb, PARALLEL_DIRECTORY, TEMP_DIRECTORY } from '../../driver.mjs';
import { ALERT_TAG, CURSOR_TAG, driver, type mongodb, PARALLEL_DIRECTORY, READ_TAG, SPEC_TAG, TEMP_DIRECTORY } from '../../driver.mjs';

export const taskSize = 262.144;
export const tags = [SPEC_TAG, ALERT_TAG, READ_TAG, CURSOR_TAG];

let bucket: mongodb.GridFSBucket;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import path from 'node:path';
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';

import { driver, type mongodb, PARALLEL_DIRECTORY } from '../../driver.mjs';
import { ALERT_TAG, driver, type mongodb, PARALLEL_DIRECTORY, SPEC_TAG, WRITE_TAG } from '../../driver.mjs';

export const taskSize = 262.144;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

let bucket: mongodb.GridFSBucket;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import path from 'node:path';
import readline from 'node:readline/promises';
import stream from 'node:stream/promises';

import { driver, EJSON, type mongodb, PARALLEL_DIRECTORY, TEMP_DIRECTORY } from '../../driver.mjs';
import { ALERT_TAG, driver, EJSON, type mongodb, PARALLEL_DIRECTORY, SPEC_TAG, TEMP_DIRECTORY, WRITE_TAG } from '../../driver.mjs';

export const taskSize = 565;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

let collection: mongodb.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { createReadStream, promises as fs } from 'node:fs';
import path from 'node:path';
import readline from 'node:readline/promises';

import { driver, type mongodb, PARALLEL_DIRECTORY } from '../../driver.mjs';
import { ALERT_TAG, driver, type mongodb, PARALLEL_DIRECTORY, SPEC_TAG, WRITE_TAG } from '../../driver.mjs';

export const taskSize = 565;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

const directory = path.resolve(PARALLEL_DIRECTORY, 'ldjson_multi');
let collection: mongodb.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, CURSOR_TAG, driver, READ_TAG, SPEC_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 16.22;
export const tags = [SPEC_TAG, ALERT_TAG, CURSOR_TAG, READ_TAG];

let collection: mongodb.Collection<{ _id: number }>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, SPEC_TAG, WRITE_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 27.31;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

let collection: mongodb.Collection;
let documents: Record<string, any>[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, SPEC_TAG, type mongodb } from '../../driver.mjs';

// { hello: true } is 13 bytes of BSON x 10,000 iterations
export const taskSize = 0.13;
export const tags = [SPEC_TAG, ALERT_TAG];

let db: mongodb.Db;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { driver, type mongodb } from '../../driver.mjs';
import { ALERT_TAG, driver, SPEC_TAG, WRITE_TAG, type mongodb } from '../../driver.mjs';

export const taskSize = 2.75;
export const tags = [SPEC_TAG, ALERT_TAG, WRITE_TAG];

let collection: mongodb.Collection;
let documents: Record<string, any>[];
Expand Down