Skip to content

Commit

Permalink
chore: test isolation and info
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Nov 21, 2024
1 parent 90cc399 commit a9de6b8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,15 @@ export async function makeSocket(options: MakeConnectionOptions): Promise<Stream
if (existingSocket) {
resolve(socket);
} else {
const connectEvent = useTLS ? 'secureConnect' : 'connect';
const start = performance.now();
const connectEvent = useTLS ? 'secureConnect' : 'connect';
socket
.once(connectEvent, () => resolve(socket))
.once('error', error => reject(connectionFailureError('error', error)))
.once('timeout', () => {
const end = performance.now();
return reject(
reject(
new MongoNetworkTimeoutError(
`socket.connect() timed out! connectTimeoutMS=${connectTimeoutMS}ms, socket.setTimeout fired after ${end - start}ms.`
`Socket '${connectEvent}' timed out after ${(performance.now() - start) | 0}ms (connectTimeoutMS: ${connectTimeoutMS})`
)
);
})
Expand Down
56 changes: 51 additions & 5 deletions test/benchmarks/driverBench/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,50 @@ 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 child_process = require('child_process');

const MONGODB_DRIVER_PATH = (() => {
let driverPath = process.env.MONGODB_DRIVER_PATH;
if (!driverPath?.length) {
driverPath = path.resolve(__dirname, '../../..');
}
return driverPath;
})();

const { MongoClient, GridFSBucket } = require(MONGODB_DRIVER_PATH);

const { version: MONGODB_DRIVER_VERSION } = require(path.join(MONGODB_DRIVER_PATH, 'package.json'));

const MONGODB_DRIVER_REVISION = (() => {
try {
return child_process
.execSync('git rev-parse --short HEAD', {
cwd: MONGODB_DRIVER_PATH,
encoding: 'utf8'
})
.trim();
} catch {
return 'unknown revision';
}
})();

const MONGODB_BSON_PATH = path.join(MONGODB_DRIVER_PATH, 'node_modules', 'bson');
const { version: MONGODB_BSON_VERSION } = require(path.join(MONGODB_BSON_PATH, 'package.json'));
const MONGODB_BSON_REVISION = (() => {
if (!fs.existsSync(path.join(MONGODB_BSON_PATH, '.git'))) {
return 'installed from npm';
}
try {
return child_process
.execSync('git rev-parse --short HEAD', {
cwd: path.join(MONGODB_BSON_PATH),
encoding: 'utf8'
})
.trim();
} catch {
return 'unknown revision';
}
})();

const DB_NAME = 'perftest';
const COLLECTION_NAME = 'corpus';
Expand Down Expand Up @@ -67,7 +107,7 @@ function initCollection() {

function dropCollection() {
return this.collection.drop().catch(e => {
if (e.code !== MONGODB_ERROR_CODES.NamespaceNotFound) {
if (e.code !== 26 /* NamespaceNotFound */) {
throw e;
}
});
Expand Down Expand Up @@ -117,6 +157,12 @@ async function writeSingleByteFileToBucket() {
module.exports = {
MONGODB_URI,
MONGODB_CLIENT_OPTIONS,
MONGODB_DRIVER_PATH,
MONGODB_DRIVER_VERSION,
MONGODB_DRIVER_REVISION,
MONGODB_BSON_PATH,
MONGODB_BSON_VERSION,
MONGODB_BSON_REVISION,
makeClient,
connectClient,
disconnectClient,
Expand Down
36 changes: 24 additions & 12 deletions test/benchmarks/driverBench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const MongoBench = require('../mongoBench');
const os = require('node:os');
const util = require('node:util');
const process = require('node:process');

const Runner = MongoBench.Runner;
Expand All @@ -11,9 +12,17 @@ let bsonType = 'js-bson';

const { writeFile } = require('fs/promises');
const {
makeParallelBenchmarks /* makeSingleBench, makeMultiBench*/
makeParallelBenchmarks /* makeSingleBench, makeMultiBench */
} = require('../mongoBench/suites');
const { MONGODB_CLIENT_OPTIONS } = require('./common');
const {
MONGODB_CLIENT_OPTIONS,
MONGODB_DRIVER_PATH,
MONGODB_DRIVER_VERSION,
MONGODB_DRIVER_REVISION,
MONGODB_BSON_PATH,
MONGODB_BSON_VERSION,
MONGODB_BSON_REVISION
} = require('./common');

const hw = os.cpus();
const ram = os.totalmem() / 1024 ** 3;
Expand All @@ -26,7 +35,10 @@ const systemInfo = () =>
`- arch: ${os.arch()}`,
`- os: ${process.platform} (${os.release()})`,
`- ram: ${platform.ram}`,
`- node: ${process.version}\n`
`- node: ${process.version}`,
`- driver: ${MONGODB_DRIVER_VERSION} (${MONGODB_DRIVER_REVISION}): ${MONGODB_DRIVER_PATH}`,
` - options ${util.inspect(MONGODB_CLIENT_OPTIONS)}`,
`- bson: ${MONGODB_BSON_VERSION} (${MONGODB_BSON_REVISION}): (${MONGODB_BSON_PATH})\n`
].join('\n');
console.log(systemInfo());

Expand Down Expand Up @@ -57,18 +69,18 @@ benchmarkRunner
]);

const readBench = average([
microBench.singleBench.findOne,
microBench.multiBench.findManyAndEmptyCursor,
microBench.multiBench.gridFsDownload,
// microBench.singleBench.findOne,
// microBench.multiBench.findManyAndEmptyCursor,
// microBench.multiBench.gridFsDownload,
microBench.parallel.gridfsMultiFileDownload,
microBench.parallel.ldjsonMultiFileExport
]);
const writeBench = average([
microBench.singleBench.smallDocInsertOne,
microBench.singleBench.largeDocInsertOne,
microBench.multiBench.smallDocBulkInsert,
microBench.multiBench.largeDocBulkInsert,
microBench.multiBench.gridFsUpload,
// microBench.singleBench.smallDocInsertOne,
// microBench.singleBench.largeDocInsertOne,
// microBench.multiBench.smallDocBulkInsert,
// microBench.multiBench.largeDocBulkInsert,
// microBench.multiBench.gridFsUpload,
microBench.parallel.ldjsonMultiFileUpload,
microBench.parallel.gridfsMultiFileUpload
]);
Expand Down Expand Up @@ -111,6 +123,6 @@ benchmarkRunner
return writeFile('results.json', results);
})
.catch(err => {
console.error('failure: ', err.name, err.message);
console.error('failure: ', err.name, err.message, err.stack);
process.exit(1);
});

0 comments on commit a9de6b8

Please sign in to comment.