diff --git a/src/cmap/connect.ts b/src/cmap/connect.ts index 8c549d42bd..e36829b72e 100644 --- a/src/cmap/connect.ts +++ b/src/cmap/connect.ts @@ -386,16 +386,15 @@ export async function makeSocket(options: MakeConnectionOptions): Promise 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})` ) ); }) diff --git a/test/benchmarks/driverBench/common.js b/test/benchmarks/driverBench/common.js index d4abaac5e6..576201113f 100644 --- a/test/benchmarks/driverBench/common.js +++ b/test/benchmarks/driverBench/common.js @@ -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'; @@ -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; } }); @@ -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, diff --git a/test/benchmarks/driverBench/index.js b/test/benchmarks/driverBench/index.js index 9245b65eb7..054f96aa40 100644 --- a/test/benchmarks/driverBench/index.js +++ b/test/benchmarks/driverBench/index.js @@ -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; @@ -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; @@ -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()); @@ -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 ]); @@ -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); });