Skip to content

Commit

Permalink
test(NODE-4590): add parallel driver benchmarks (#3389)
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson authored Sep 8, 2022
1 parent f5f24f2 commit 0a2ad07
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 326 deletions.
43 changes: 41 additions & 2 deletions test/benchmarks/driverBench/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

const fs = require('fs');
const path = require('path');
const { Readable } = require('stream');
const { pipeline } = require('stream/promises');
const { MongoClient } = require('../../..');
const { GridFSBucket } = require('../../..');

// eslint-disable-next-line no-restricted-modules
const { MONGODB_ERROR_CODES } = require('../../../lib/error');

const DB_NAME = 'perftest';
const COLLECTION_NAME = 'corpus';

Expand Down Expand Up @@ -48,7 +53,11 @@ function initCollection() {
}

function dropCollection() {
return this.collection.drop();
return this.collection.drop().catch(e => {
if (e.code !== MONGODB_ERROR_CODES.NamespaceNotFound) {
throw e;
}
});
}

function initBucket() {
Expand All @@ -65,6 +74,33 @@ function makeLoadJSON(name) {
};
}

function makeLoadTweets(makeId) {
return function () {
const doc = this.doc;
const tweets = [];
for (let _id = 1; _id <= 10000; _id += 1) {
tweets.push(Object.assign({}, doc, makeId ? { _id } : {}));
}

return this.collection.insertMany(tweets);
};
}

function makeLoadInsertDocs(numberOfOperations) {
return function () {
this.docs = [];
for (let i = 0; i < numberOfOperations; i += 1) {
this.docs.push(Object.assign({}, this.doc));
}
};
}

async function writeSingleByteFileToBucket() {
const stream = this.bucket.openUploadStream('setup-file.txt');
const oneByteFile = Readable.from('a');
return pipeline(oneByteFile, stream);
}

module.exports = {
makeClient,
connectClient,
Expand All @@ -78,5 +114,8 @@ module.exports = {
loadSpecFile,
loadSpecString,
initBucket,
dropBucket
dropBucket,
makeLoadTweets,
makeLoadInsertDocs,
writeSingleByteFileToBucket
};
Loading

0 comments on commit 0a2ad07

Please sign in to comment.