Skip to content

chore(NODE-6721): migrate singlebench tests #4401

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 3 commits into from
Feb 6, 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
15 changes: 5 additions & 10 deletions test/benchmarks/driver_bench/src/driver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,16 @@ export function metrics(test_name: string, result: number, count: number) {
* For use in setup/teardown mostly.
*/
export class DriverTester {
readonly DB_NAME = DB_NAME;
readonly COLLECTION_NAME = COLLECTION_NAME;

public client: mongodb.MongoClient;
constructor() {
this.client = new MongoClient(MONGODB_URI, MONGODB_CLIENT_OPTIONS);
}

public get db() {
return this.client.db(DB_NAME);
}

public get collection() {
return this.client.db(DB_NAME).collection(COLLECTION_NAME);
}

public get bucket(): mongodb.GridFSBucket {
return new GridFSBucket(this.db);
bucket(db: mongodb.Db) {
return new GridFSBucket(db);
}

async drop() {
Expand Down
1 change: 1 addition & 0 deletions test/benchmarks/driver_bench/src/runner.mts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ console.log(
...['total time:', totalDuration, 'sec,'],
...['ran:', count, 'times,'],
...['median time per run:', medianExecution, 'sec,'],
...['taskSize:', benchmark.taskSize, 'mb,'],
...['throughput:', megabytesPerSecond, 'mb/sec']
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function before() {
await driver.drop();
await driver.create();

db = driver.db;
db = driver.client.db(driver.DB_NAME);
}

export async function run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function before() {

tweet = await driver.load('single_and_multi_document/tweet.json', 'json');

db = driver.db;
db = driver.client.db(driver.DB_NAME);
}

export async function run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function before() {
const tweet = await driver.load('single_and_multi_document/tweet.json', 'json');
await driver.insertManyOf(tweet, 10000);

collection = driver.collection;
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function before() {
const tweet = await driver.load('single_and_multi_document/tweet.json', 'json');
await driver.insertManyOf(tweet, 10000);

collection = driver.collection;
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function before() {
await driver.drop();
await driver.create();

bucket = driver.bucket;
bucket = driver.bucket(driver.client.db(driver.DB_NAME));

await bucket.drop().catch(() => null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function before() {
await driver.drop();
await driver.create();

bucket = driver.bucket;
bucket = driver.bucket(driver.client.db(driver.DB_NAME));

await bucket.drop().catch(() => null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function beforeEach() {
// Make new "documents" so the _id field is not carried over from the last run
documents = Array.from({ length: 10 }, () => ({ ...largeDoc })) as any[];

collection = driver.collection;
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function beforeEach() {
// Make new "documents" so the _id field is not carried over from the last run
documents = Array.from({ length: 10000 }, () => ({ ...smallDoc })) as any[];

collection = driver.collection;
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { driver, type mongodb } from '../../driver.mjs';

export const taskSize = 16.22;

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

export async function before() {
await driver.drop();
await driver.create();

const tweet = await driver.load('single_and_multi_document/tweet.json', 'json');
await driver.insertManyOf(tweet, 10000, true);

collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
for (let _id = 0; _id < 10000; ++_id) {
await collection.findOne({ _id });
}
}

export async function after() {
await driver.drop();
await driver.close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { driver, type mongodb } from '../../driver.mjs';

export const taskSize = 27.31;

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

export async function before() {
largeDoc = await driver.load('single_and_multi_document/large_doc.json', 'json');
}

export async function beforeEach() {
await driver.drop();
await driver.create();

// Make new "documents" so the _id field is not carried over from the last run
documents = Array.from({ length: 10 }, () => ({ ...largeDoc }));

collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
for (const doc of documents) {
await collection.insertOne(doc);
}
}

export async function after() {
await driver.drop();
await driver.close();
}
24 changes: 24 additions & 0 deletions test/benchmarks/driver_bench/src/suites/single_bench/ping.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { driver, type mongodb } from '../../driver.mjs';

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

let db: mongodb.Db;

export async function before() {
await driver.drop();
await driver.create();

db = driver.client.db(driver.DB_NAME);
}

export async function run() {
for (let i = 0; i < 10000; ++i) {
await db.command({ ping: 1 });
}
}

export async function after() {
await driver.drop();
await driver.close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { driver, type mongodb } from '../../driver.mjs';

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

let db: mongodb.Db;

export async function before() {
await driver.drop();
await driver.create();

db = driver.client.db(driver.DB_NAME);
}

export async function run() {
for (let i = 0; i < 10000; ++i) {
await db.command({ hello: true });
}
}

export async function after() {
await driver.drop();
await driver.close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { driver, type mongodb } from '../../driver.mjs';

export const taskSize = 2.75;

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

export async function before() {
smallDoc = await driver.load('single_and_multi_document/small_doc.json', 'json');
}

export async function beforeEach() {
await driver.drop();
await driver.create();

// Make new "documents" so the _id field is not carried over from the last run
documents = Array.from({ length: 10000 }, () => ({ ...smallDoc }));

collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
}

export async function run() {
for (const doc of documents) {
await collection.insertOne(doc);
}
}

export async function after() {
await driver.drop();
await driver.close();
}