Skip to content

Commit df3ea32

Browse files
authored
Merge branch 'main' into NODE-6552-fix-perf-tests
2 parents ef7ef02 + 5558573 commit df3ea32

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

src/cmap/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ export class SizedMessageTransform extends Transform {
769769
connection: Connection;
770770

771771
constructor({ connection }: { connection: Connection }) {
772-
super({ objectMode: false });
772+
super({ writableObjectMode: false, readableObjectMode: true });
773773
this.bufferPool = new BufferPool();
774774
this.connection = connection;
775775
}

test/benchmarks/mongoBench/suites/singleBench.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function makeSingleBench(suite) {
3636
)
3737
.benchmark('runCommand', benchmark =>
3838
benchmark
39-
// { hello: true } is 13 bytes. However the legacy hello was 16 bytes, to preserve history comparison data we leave this value as is.
40-
.taskSize(0.16)
39+
// { hello: true } is 13 bytes of BSON x 10,000 iterations
40+
.taskSize(0.13)
4141
.setup(makeClient)
4242
.setup(connectClient)
4343
.setup(initDb)

test/spec/connection-monitoring-and-pooling/cmap-format/pool-checkout-returned-connection-maxConnecting.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
},
2525
"poolOptions": {
26+
"maxConnecting": 2,
2627
"maxPoolSize": 10,
2728
"waitQueueTimeoutMS": 5000
2829
},
@@ -72,9 +73,8 @@
7273
"connection": "conn0"
7374
},
7475
{
75-
"name": "waitForEvent",
76-
"event": "ConnectionCheckedOut",
77-
"count": 4
76+
"name": "wait",
77+
"ms": 100
7878
}
7979
],
8080
"events": [
@@ -104,14 +104,6 @@
104104
"type": "ConnectionCheckedOut",
105105
"connectionId": 1,
106106
"address": 42
107-
},
108-
{
109-
"type": "ConnectionCheckedOut",
110-
"address": 42
111-
},
112-
{
113-
"type": "ConnectionCheckedOut",
114-
"address": 42
115107
}
116108
],
117109
"ignore": [

test/spec/connection-monitoring-and-pooling/cmap-format/pool-checkout-returned-connection-maxConnecting.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ failPoint:
1515
blockConnection: true
1616
blockTimeMS: 750
1717
poolOptions:
18+
maxConnecting: 2
1819
maxPoolSize: 10
1920
waitQueueTimeoutMS: 5000
2021
operations:
@@ -45,14 +46,13 @@ operations:
4546
count: 4
4647
- name: wait
4748
ms: 100
48-
# check original connection back in, so the thread that isn't
49-
# currently establishing will become unblocked. Then wait for
50-
# all threads to complete.
49+
# Check original connection back in, so one of the waiting threads can check
50+
# out the idle connection before the two new connections are ready.
5151
- name: checkIn
5252
connection: conn0
53-
- name: waitForEvent
54-
event: ConnectionCheckedOut
55-
count: 4
53+
# Wait for 100ms to let one of the blocked checkOut operations complete.
54+
- name: wait
55+
ms: 100
5656
events:
5757
# main thread checking out a Connection and holding it
5858
- type: ConnectionCreated
@@ -69,15 +69,13 @@ events:
6969
- type: ConnectionCheckedIn
7070
connectionId: 1
7171
address: 42
72-
# remaining thread checking out the returned Connection
72+
# Another thread checks out the returned Connection before the two new
73+
# connections are checked out.
7374
- type: ConnectionCheckedOut
7475
connectionId: 1
7576
address: 42
76-
# first two threads finishing Connection establishment
77-
- type: ConnectionCheckedOut
78-
address: 42
79-
- type: ConnectionCheckedOut
80-
address: 42
77+
# Events after this can come in different orders but still be valid.
78+
# See DRIVERS-2223 for details.
8179
ignore:
8280
- ConnectionPoolReady
8381
- ConnectionClosed

test/unit/cmap/connection.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
MongoClientAuthProviders,
1212
MongoDBCollectionNamespace,
1313
MongoNetworkTimeoutError,
14-
ns
14+
ns,
15+
SizedMessageTransform
1516
} from '../../mongodb';
1617
import * as mock from '../../tools/mongodb-mock/index';
1718
import { getSymbolFrom } from '../../tools/utils';
@@ -323,4 +324,19 @@ describe('new Connection()', function () {
323324
});
324325
});
325326
});
327+
328+
describe('SizedMessageTransform', function () {
329+
it('parses chunks of wire messages', function () {
330+
const stream = new SizedMessageTransform({ connection: {} as any });
331+
// Message of length 4 + 4 = 8
332+
stream.write(Buffer.from([8, 0, 0, 0]));
333+
stream.write(Buffer.from([1, 2, 3, 4]));
334+
// Message of length 4 + 2 = 6, chunked differently
335+
stream.write(Buffer.from([6, 0, 0]));
336+
stream.write(Buffer.from([0, 5, 6]));
337+
expect(stream.read(1)).to.deep.equal(Buffer.from([8, 0, 0, 0, 1, 2, 3, 4]));
338+
expect(stream.read(1)).to.deep.equal(Buffer.from([6, 0, 0, 0, 5, 6]));
339+
expect(stream.read(1)).to.equal(null);
340+
});
341+
});
326342
});

0 commit comments

Comments
 (0)