File tree Expand file tree Collapse file tree 4 files changed +105
-1
lines changed
test/benchmarks/driverBench Expand file tree Collapse file tree 4 files changed +105
-1
lines changed Original file line number Diff line number Diff line change
1
+ const totalStart = performance . now ( ) ;
2
+ /* eslint-disable no-console */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+ const process = require ( 'node:process' ) ;
5
+ const { MongoClient } = require ( './lib/index.js' ) ;
6
+ const { ModernConnection } = require ( './lib/cmap/connection.js' ) ;
7
+
8
+ const tweet = require ( './test/benchmarks/driverBench/spec/single_and_multi_document/tweet.json' ) ;
9
+
10
+ const client = new MongoClient ( process . env . MONGODB_URI , { connectionType : ModernConnection } ) ;
11
+
12
+ async function main ( ) {
13
+ console . log ( 'modern connection' ) ;
14
+
15
+ const db = client . db ( 'test' ) ;
16
+ let collection = db . collection ( 'test' ) ;
17
+ await collection . drop ( ) . catch ( ( ) => null ) ;
18
+ collection = await db . createCollection ( 'test' ) ;
19
+ await collection . insertOne ( tweet ) ;
20
+
21
+ const total = 10_000 ;
22
+
23
+ for ( let i = 0 ; i < total ; i ++ ) {
24
+ await collection . findOne ( ) ;
25
+ }
26
+
27
+ const start = performance . now ( ) - totalStart ;
28
+ for ( let i = 0 ; i < total ; i ++ ) {
29
+ await collection . findOne ( ) ;
30
+ }
31
+ const end = performance . now ( ) - totalStart ;
32
+
33
+ console . log (
34
+ `end - start = ms time for 10k findOne calls (script boot: ${ totalStart . toFixed ( 3 ) } )`
35
+ ) ;
36
+ console . log ( `${ end . toFixed ( 3 ) } - ${ start . toFixed ( 3 ) } = ${ ( end - start ) . toFixed ( 4 ) } ` ) ;
37
+ console . log ( `avg findOne: ${ ( ( end - start ) / total ) . toFixed ( 3 ) } ms` ) ;
38
+
39
+ await client . close ( ) ;
40
+ }
41
+
42
+ main ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change
1
+ const totalStart = performance . now ( ) ;
2
+ /* eslint-disable no-console */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+ const process = require ( 'node:process' ) ;
5
+ const { MongoClient } = require ( './lib/index.js' ) ;
6
+ const { Connection } = require ( './lib/cmap/connection.js' ) ;
7
+
8
+ const tweet = require ( './test/benchmarks/driverBench/spec/single_and_multi_document/tweet.json' ) ;
9
+
10
+ const client = new MongoClient ( process . env . MONGODB_URI , { connectionType : Connection } ) ;
11
+
12
+ async function main ( ) {
13
+ console . log ( 'old connection' ) ;
14
+
15
+ const db = client . db ( 'test' ) ;
16
+ let collection = db . collection ( 'test' ) ;
17
+ await collection . drop ( ) . catch ( ( ) => null ) ;
18
+ collection = await db . createCollection ( 'test' ) ;
19
+ await collection . insertOne ( tweet ) ;
20
+
21
+ const total = 10_000 ;
22
+
23
+ for ( let i = 0 ; i < total ; i ++ ) {
24
+ await collection . findOne ( ) ;
25
+ }
26
+
27
+ const start = performance . now ( ) - totalStart ;
28
+ for ( let i = 0 ; i < total ; i ++ ) {
29
+ await collection . findOne ( ) ;
30
+ }
31
+ const end = performance . now ( ) - totalStart ;
32
+
33
+ console . log (
34
+ `end - start = ms time for 10k findOne calls (script boot: ${ totalStart . toFixed ( 3 ) } )`
35
+ ) ;
36
+ console . log ( `${ end . toFixed ( 3 ) } - ${ start . toFixed ( 3 ) } = ${ ( end - start ) . toFixed ( 4 ) } ` ) ;
37
+ console . log ( `avg findOne: ${ ( ( end - start ) / total ) . toFixed ( 3 ) } ms` ) ;
38
+
39
+ await client . close ( ) ;
40
+ }
41
+
42
+ main ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ const { Readable } = require('stream');
6
6
const { pipeline } = require ( 'stream/promises' ) ;
7
7
const { MongoClient } = require ( '../../..' ) ;
8
8
const { GridFSBucket } = require ( '../../..' ) ;
9
+ // eslint-disable-next-line no-restricted-modules
10
+ const { ModernConnection, Connection } = require ( '../../../lib/cmap/connection' ) ;
9
11
10
12
// eslint-disable-next-line no-restricted-modules
11
13
const { MONGODB_ERROR_CODES } = require ( '../../../lib/error' ) ;
@@ -25,7 +27,9 @@ function loadSpecString(filePath) {
25
27
}
26
28
27
29
function makeClient ( ) {
28
- this . client = new MongoClient ( process . env . MONGODB_URI || 'mongodb://localhost:27017' ) ;
30
+ this . client = new MongoClient ( process . env . MONGODB_URI || 'mongodb://127.0.0.1:27017' , {
31
+ connectionType : Connection
32
+ } ) ;
29
33
}
30
34
31
35
function connectClient ( ) {
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const MongoBench = require ( '../mongoBench' ) ;
4
+ const os = require ( 'node:os' ) ;
4
5
5
6
const Runner = MongoBench . Runner ;
6
7
@@ -11,6 +12,21 @@ const { inspect } = require('util');
11
12
const { writeFile } = require ( 'fs/promises' ) ;
12
13
const { makeParallelBenchmarks, makeSingleBench, makeMultiBench } = require ( '../mongoBench/suites' ) ;
13
14
15
+ const hw = os . cpus ( ) ;
16
+ const ram = os . totalmem ( ) / 1024 ** 3 ;
17
+ const platform = { name : hw [ 0 ] . model , cores : hw . length , ram : `${ ram } GB` } ;
18
+
19
+ const systemInfo = ( ) =>
20
+ [
21
+ `Connection` ,
22
+ `\n- cpu: ${ platform . name } ` ,
23
+ `- cores: ${ platform . cores } ` ,
24
+ `- arch: ${ os . arch ( ) } ` ,
25
+ `- os: ${ process . platform } (${ os . release ( ) } )` ,
26
+ `- ram: ${ platform . ram } `
27
+ ] . join ( '\n' ) ;
28
+ console . log ( systemInfo ( ) ) ;
29
+
14
30
function average ( arr ) {
15
31
return arr . reduce ( ( x , y ) => x + y , 0 ) / arr . length ;
16
32
}
You can’t perform that action at this time.
0 commit comments