Skip to content

Commit 0a2ad07

Browse files
test(NODE-4590): add parallel driver benchmarks (#3389)
1 parent f5f24f2 commit 0a2ad07

File tree

7 files changed

+602
-326
lines changed

7 files changed

+602
-326
lines changed

test/benchmarks/driverBench/common.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
const fs = require('fs');
44
const path = require('path');
5+
const { Readable } = require('stream');
6+
const { pipeline } = require('stream/promises');
57
const { MongoClient } = require('../../..');
68
const { GridFSBucket } = require('../../..');
79

10+
// eslint-disable-next-line no-restricted-modules
11+
const { MONGODB_ERROR_CODES } = require('../../../lib/error');
12+
813
const DB_NAME = 'perftest';
914
const COLLECTION_NAME = 'corpus';
1015

@@ -48,7 +53,11 @@ function initCollection() {
4853
}
4954

5055
function dropCollection() {
51-
return this.collection.drop();
56+
return this.collection.drop().catch(e => {
57+
if (e.code !== MONGODB_ERROR_CODES.NamespaceNotFound) {
58+
throw e;
59+
}
60+
});
5261
}
5362

5463
function initBucket() {
@@ -65,6 +74,33 @@ function makeLoadJSON(name) {
6574
};
6675
}
6776

77+
function makeLoadTweets(makeId) {
78+
return function () {
79+
const doc = this.doc;
80+
const tweets = [];
81+
for (let _id = 1; _id <= 10000; _id += 1) {
82+
tweets.push(Object.assign({}, doc, makeId ? { _id } : {}));
83+
}
84+
85+
return this.collection.insertMany(tweets);
86+
};
87+
}
88+
89+
function makeLoadInsertDocs(numberOfOperations) {
90+
return function () {
91+
this.docs = [];
92+
for (let i = 0; i < numberOfOperations; i += 1) {
93+
this.docs.push(Object.assign({}, this.doc));
94+
}
95+
};
96+
}
97+
98+
async function writeSingleByteFileToBucket() {
99+
const stream = this.bucket.openUploadStream('setup-file.txt');
100+
const oneByteFile = Readable.from('a');
101+
return pipeline(oneByteFile, stream);
102+
}
103+
68104
module.exports = {
69105
makeClient,
70106
connectClient,
@@ -78,5 +114,8 @@ module.exports = {
78114
loadSpecFile,
79115
loadSpecString,
80116
initBucket,
81-
dropBucket
117+
dropBucket,
118+
makeLoadTweets,
119+
makeLoadInsertDocs,
120+
writeSingleByteFileToBucket
82121
};

0 commit comments

Comments
 (0)