From e5a7c4c4a1c5dfc7644426e84cbdca832bd265a5 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 25 Nov 2024 11:54:53 -0500 Subject: [PATCH] chore: prepare for BSON fix --- src/cmap/connect.ts | 58 +++++++++++-------------- test/benchmarks/driverBench/common.js | 22 ++++++++++ test/benchmarks/driverBench/index.js | 62 +++++++++++---------------- 3 files changed, 73 insertions(+), 69 deletions(-) diff --git a/src/cmap/connect.ts b/src/cmap/connect.ts index e36829b72e..9efe246107 100644 --- a/src/cmap/connect.ts +++ b/src/cmap/connect.ts @@ -390,7 +390,9 @@ export async function makeSocket(options: MakeConnectionOptions): Promise resolve(socket)) - .once('error', error => reject(connectionFailureError('error', error))) + .once('error', cause => + reject(new MongoNetworkError(MongoError.buildErrorMessage(cause), { cause })) + ) .once('timeout', () => { reject( new MongoNetworkTimeoutError( @@ -398,10 +400,21 @@ export async function makeSocket(options: MakeConnectionOptions): Promise reject(connectionFailureError('close'))); + .once('close', () => + reject( + new MongoNetworkError( + `Socket closed after ${(performance.now() - start) | 0} during connection establishment` + ) + ) + ); if (options.cancellationToken != null) { - cancellationHandler = () => reject(connectionFailureError('cancel')); + cancellationHandler = () => + reject( + new MongoNetworkError( + `Socket connection establishment was cancelled after ${(performance.now() - start) | 0}` + ) + ); options.cancellationToken.once('cancel', cancellationHandler); } } @@ -454,9 +467,11 @@ async function makeSocks5Connection(options: MakeConnectionOptions): Promise { let driverPath = process.env.MONGODB_DRIVER_PATH; if (!driverPath?.length) { @@ -16,8 +21,13 @@ const MONGODB_DRIVER_PATH = (() => { const { MongoClient, GridFSBucket } = require(MONGODB_DRIVER_PATH); +/** Grab the version from the package.json */ const { version: MONGODB_DRIVER_VERSION } = require(path.join(MONGODB_DRIVER_PATH, 'package.json')); +/** + * Use git to optionally determine the git revision, + * but the benchmarks could be run against an npm installed version so this should be allowed to fail + */ const MONGODB_DRIVER_REVISION = (() => { try { return child_process @@ -31,8 +41,20 @@ const MONGODB_DRIVER_REVISION = (() => { } })(); +/** + * Find the BSON dependency inside the driver PATH given and grab the version from the package.json. + */ 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')); + +/** + * If you need to test BSON changes, you should clone, checkout and build BSON. + * run: `npm link` with no arguments to register the link. + * Then in the driver you are testing run `npm link bson` to use your local build. + * + * This will symlink the BSON into the driver's node_modules directory. So here + * we can find the revision of the BSON we are testing against if .git exists. + */ const MONGODB_BSON_REVISION = (() => { if (!fs.existsSync(path.join(MONGODB_BSON_PATH, '.git'))) { return 'installed from npm'; diff --git a/test/benchmarks/driverBench/index.js b/test/benchmarks/driverBench/index.js index 054f96aa40..34e10206a4 100644 --- a/test/benchmarks/driverBench/index.js +++ b/test/benchmarks/driverBench/index.js @@ -2,7 +2,6 @@ const MongoBench = require('../mongoBench'); const os = require('node:os'); -const util = require('node:util'); const process = require('node:process'); const Runner = MongoBench.Runner; @@ -11,18 +10,8 @@ let bsonType = 'js-bson'; // TODO(NODE-4606): test against different driver configurations in CI const { writeFile } = require('fs/promises'); -const { - makeParallelBenchmarks /* makeSingleBench, makeMultiBench */ -} = require('../mongoBench/suites'); -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 { makeParallelBenchmarks, makeSingleBench, makeMultiBench } = require('../mongoBench/suites'); +const { MONGODB_CLIENT_OPTIONS } = require('./common'); const hw = os.cpus(); const ram = os.totalmem() / 1024 ** 3; @@ -35,10 +24,7 @@ const systemInfo = () => `- arch: ${os.arch()}`, `- os: ${process.platform} (${os.release()})`, `- ram: ${platform.ram}`, - `- 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` + `- node: ${process.version}\n` ].join('\n'); console.log(systemInfo()); @@ -47,19 +33,23 @@ function average(arr) { } const benchmarkRunner = new Runner() - // .suite('singleBench', suite => makeSingleBench(suite)) - // .suite('multiBench', suite => makeMultiBench(suite)) + .suite('singleBench', suite => makeSingleBench(suite)) + .suite('multiBench', suite => makeMultiBench(suite)) .suite('parallel', suite => makeParallelBenchmarks(suite)); benchmarkRunner .run() .then(microBench => { - // const singleBench = average([ - // microBench.singleBench.findOne, - // microBench.singleBench.smallDocInsertOne, - // microBench.singleBench.largeDocInsertOne - // ]); - // const multiBench = average(Object.values(microBench.multiBench)); + const singleBench = average([ + microBench.singleBench.findOne, + microBench.singleBench.smallDocInsertOne, + microBench.singleBench.largeDocInsertOne + ]); + const multiBench = average(Object.values(microBench.multiBench)); + + // ldjsonMultiFileUpload and ldjsonMultiFileExport cause connection errors. + // While we investigate, we will use the last known good values: + // https://spruce.mongodb.com/task/mongo_node_driver_next_performance_tests_run_spec_benchmark_tests_node_server_4bc3e500b6f0e8ab01f052c4a1bfb782d6a29b4e_f168e1328f821bbda265e024cc91ae54_24_11_18_15_37_24/logs?execution=0 const parallelBench = average([ microBench.parallel.ldjsonMultiFileUpload, @@ -69,18 +59,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 ]); @@ -88,8 +78,8 @@ benchmarkRunner const driverBench = average([readBench, writeBench]); const benchmarkResults = { - // singleBench, - // multiBench, + singleBench, + multiBench, parallelBench, readBench, writeBench, @@ -123,6 +113,6 @@ benchmarkRunner return writeFile('results.json', results); }) .catch(err => { - console.error('failure: ', err.name, err.message, err.stack); + console.error('failure: ', err.name, err.message); process.exit(1); });