Skip to content

Commit 8e8db00

Browse files
authored
DRIVERS-2469 Add durations to connection pool events (#1448)
DRIVERS-2469
1 parent db7eb39 commit 8e8db00

File tree

5 files changed

+123
-11
lines changed

5 files changed

+123
-11
lines changed

source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Abstract
1212

1313
Drivers currently support a variety of options that allow users to configure connection pooling behavior. Users are confused by drivers supporting different subsets of these options. Additionally, drivers implement their connection pools differently, making it difficult to design cross-driver pool functionality. By unifying and codifying pooling options and behavior across all drivers, we will increase user comprehension and code base maintainability.
1414

15+
This specification does not apply to drivers that do not support multitasking.
16+
1517
META
1618
====
1719

@@ -131,8 +133,9 @@ Additionally, Drivers that implement a Connection Pool MUST support the followin
131133
/**
132134
* NOTE: This option has been deprecated in favor of timeoutMS.
133135
*
134-
* The maximum amount of time a thread can wait for a connection
135-
* to become available.
136+
* The maximum amount of time a thread can wait for
137+
* either an available non-perished connection (limited by `maxPoolSize`),
138+
* or a pending connection (limited by `maxConnecting`).
136139
* If specified, MUST be a number >= 0.
137140
* A value of 0 means there is no limit.
138141
* Defaults to 0.
@@ -641,12 +644,6 @@ Before a given `Connection <#connection>`_ is returned from checkOut, it must be
641644
# This must be done in all drivers
642645
leave wait queue
643646
644-
# If there is no background thread, the pool MUST ensure that
645-
# there are at least minPoolSize total connections.
646-
# This MUST be done in a non-blocking manner
647-
while totalConnectionCount < minPoolSize:
648-
populate the pool with a connection
649-
650647
# If the Connection has not been established yet (TCP, TLS,
651648
# handshake, compression, and auth), it must be established
652649
# before it is returned.
@@ -663,6 +660,13 @@ Before a given `Connection <#connection>`_ is returned from checkOut, it must be
663660
else:
664661
decrement availableConnectionCount
665662
set connection state to "in use"
663+
664+
# If there is no background thread, the pool MUST ensure that
665+
# there are at least minPoolSize total connections.
666+
do asynchronously:
667+
while totalConnectionCount < minPoolSize:
668+
populate the pool with a connection
669+
666670
emit ConnectionCheckedOutEvent and equivalent log message
667671
return connection
668672
@@ -909,6 +913,30 @@ See the `Load Balancer Specification <../load-balancers/load-balancers.rst#event
909913
* The ID of the Connection
910914
*/
911915
connectionId: int64;
916+
917+
/**
918+
* The time it took to establish the connection.
919+
* In accordance with the definition of establishment of a connection
920+
* specified by `ConnectionPoolOptions.maxConnecting`,
921+
* it is the time elapsed between the `ConnectionCreatedEvent`
922+
* emitted by the same checking out and this event.
923+
*
924+
* Naturally, when establishing a connection is part of checking out,
925+
* this duration is not greater than
926+
* `ConnectionCheckedOutEvent`/`ConnectionCheckOutFailedEvent.duration`.
927+
*
928+
* A driver that delivers events synchronously MUST NOT include in this duration
929+
* the time to deliver the `ConnectionCreatedEvent`.
930+
* Doing so eliminates a thing to worry about in support cases related to this duration,
931+
* because the time to deliver synchronously is affected by user code.
932+
* The driver MUST document this behavior
933+
* as well as explicitly warn users that the behavior may change in the future.
934+
*
935+
* A driver MAY choose the type idiomatic to the driver.
936+
* If the type chosen does not convey units, e.g., `int64`,
937+
* then the driver MAY include units in the name, e.g., `durationMS`.
938+
*/
939+
duration: Duration;
912940
}
913941
914942
/**
@@ -966,6 +994,11 @@ See the `Load Balancer Specification <../load-balancers/load-balancers.rst#event
966994
* - "connectionError": The Connection check out attempt experienced an error while setting up a new Connection
967995
*/
968996
reason: string|Enum;
997+
998+
/**
999+
* See `ConnectionCheckedOutEvent.duration`.
1000+
*/
1001+
duration: Duration;
9691002
}
9701003
9711004
/**
@@ -981,6 +1014,32 @@ See the `Load Balancer Specification <../load-balancers/load-balancers.rst#event
9811014
* The ID of the Connection
9821015
*/
9831016
connectionId: int64;
1017+
1018+
/**
1019+
* The time it took to check out the connection.
1020+
* More specifically, the time elapsed between
1021+
* the `ConnectionCheckOutStartedEvent`
1022+
* emitted by the same checking out and this event.
1023+
*
1024+
* Naturally, if a new connection was not created (`ConnectionCreatedEvent`)
1025+
* and established (`ConnectionReadyEvent`) as part of checking out,
1026+
* this duration is usually
1027+
* not greater than `ConnectionPoolOptions.waitQueueTimeoutMS`,
1028+
* but MAY occasionally be greater than that,
1029+
* because a driver does not provide hard real-time guarantees.
1030+
*
1031+
* A driver that delivers events synchronously MUST NOT include in this duration
1032+
* the time to deliver the `ConnectionCheckOutStartedEvent`.
1033+
* Doing so eliminates a thing to worry about in support cases related to this duration,
1034+
* because the time to deliver synchronously is affected by user code.
1035+
* The driver MUST document this behavior
1036+
* as well as explicitly warn users that the behavior may change in the future.
1037+
*
1038+
* A driver MAY choose the type idiomatic to the driver.
1039+
* If the type chosen does not convey units, e.g., `int64`,
1040+
* then the driver MAY include units in the name, e.g., `durationMS`.
1041+
*/
1042+
duration: Duration;
9841043
}
9851044
9861045
/**
@@ -1195,9 +1254,13 @@ In addition to the common fields defined above, this message MUST contain the fo
11951254
- Int64
11961255
- The driver-generated ID for the connection as defined in `Connection <#connection>`_.
11971256

1257+
* - durationMS
1258+
- Int64
1259+
- ``ConnectionReadyEvent.duration`` converted to milliseconds.
1260+
11981261
The unstructured form SHOULD be as follows, using the values defined in the structured format above to fill in placeholders as appropriate:
11991262

1200-
Connection ready: address={{serverHost}}:{{serverPort}}, driver-generated ID={{driverConnectionId}}
1263+
Connection ready: address={{serverHost}}:{{serverPort}}, driver-generated ID={{driverConnectionId}}, established in={{durationMS}} ms
12011264

12021265
Connection Closed Message
12031266
-------------------------
@@ -1288,9 +1351,13 @@ In addition to the common fields defined above, this message MUST contain the fo
12881351
- If ``reason`` is ``ConnectionError``, the associated error. The type and format of this value is flexible; see the
12891352
`logging specification <../logging/logging.rst#representing-errors-in-log-messages>`_ for details on representing errors in log messages.
12901353

1354+
* - durationMS
1355+
- Int64
1356+
- ``ConnectionCheckOutFailedEvent.duration`` converted to milliseconds.
1357+
12911358
The unstructured form SHOULD be as follows, using the values defined in the structured format above to fill in placeholders as appropriate:
12921359

1293-
Checkout failed for connection to {{serverHost}}:{{serverPort}}. Reason: {{reason}}. Error: {{error}}
1360+
Checkout failed for connection to {{serverHost}}:{{serverPort}}. Reason: {{reason}}. Error: {{error}}. Duration: {{durationMS}} ms
12941361

12951362
Connection Checked Out
12961363
-----------------------
@@ -1312,9 +1379,13 @@ In addition to the common fields defined above, this message MUST contain the fo
13121379
- Int64
13131380
- The driver-generated ID for the connection as defined in `Connection <#connection>`_.
13141381

1382+
* - durationMS
1383+
- Int64
1384+
- ``ConnectionCheckedOutEvent.duration`` converted to milliseconds.
1385+
13151386
The unstructured form SHOULD be as follows, using the values defined in the structured format above to fill in placeholders as appropriate:
13161387

1317-
Connection checked out: address={serverHost}}:{{serverPort}}, driver-generated ID={{driverConnectionId}}
1388+
Connection checked out: address={serverHost}}:{{serverPort}}, driver-generated ID={{driverConnectionId}}, duration={{durationMS}} ms
13181389

13191390
Connection Checked In
13201391
---------------------
@@ -1549,6 +1620,7 @@ Changelog
15491620
:2022-10-05: Remove spec front matter and reformat changelog.
15501621
:2022-10-14: Add connection pool log messages and associated tests.
15511622
:2023-04-17: Fix duplicate logging test description.
1623+
:2023-08-04: Add durations to connection pool events.
15521624

15531625
----
15541626

source/connection-monitoring-and-pooling/tests/logging/connection-logging.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
"int",
141141
"long"
142142
]
143+
},
144+
"durationMS": {
145+
"$$type": [
146+
"double",
147+
"int",
148+
"long"
149+
]
143150
}
144151
}
145152
},
@@ -162,6 +169,13 @@
162169
"int",
163170
"long"
164171
]
172+
},
173+
"durationMS": {
174+
"$$type": [
175+
"double",
176+
"int",
177+
"long"
178+
]
165179
}
166180
}
167181
},
@@ -222,6 +236,13 @@
222236
"int",
223237
"long"
224238
]
239+
},
240+
"durationMS": {
241+
"$$type": [
242+
"double",
243+
"int",
244+
"long"
245+
]
225246
}
226247
}
227248
},
@@ -484,6 +505,13 @@
484505
"reason": "An error occurred while trying to establish a new connection",
485506
"error": {
486507
"$$exists": true
508+
},
509+
"durationMS": {
510+
"$$type": [
511+
"double",
512+
"int",
513+
"long"
514+
]
487515
}
488516
}
489517
}

source/connection-monitoring-and-pooling/tests/logging/connection-logging.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ tests:
6666
driverConnectionId: { $$type: [int, long] }
6767
serverHost: { $$type: string }
6868
serverPort: { $$type: [int, long] }
69+
durationMS: { $$type: [double, int, long] }
6970

7071
- level: debug
7172
component: connection
@@ -74,6 +75,7 @@ tests:
7475
driverConnectionId: { $$type: [int, long] }
7576
serverHost: { $$type: string }
7677
serverPort: { $$type: [int, long] }
78+
durationMS: { $$type: [double, int, long] }
7779

7880
- level: debug
7981
component: connection
@@ -98,6 +100,7 @@ tests:
98100
driverConnectionId: { $$type: [int, long] }
99101
serverHost: { $$type: string }
100102
serverPort: { $$type: [int, long] }
103+
durationMS: { $$type: [double, int, long] }
101104

102105
- level: debug
103106
component: connection
@@ -218,3 +221,4 @@ tests:
218221
serverPort: { $$type: [int, long] }
219222
reason: "An error occurred while trying to establish a new connection"
220223
error: { $$exists: true }
224+
durationMS: { $$type: [double, int, long] }

source/connection-monitoring-and-pooling/tests/logging/connection-pool-options.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@
128128
"int",
129129
"long"
130130
]
131+
},
132+
"durationMS": {
133+
"$$type": [
134+
"double",
135+
"int",
136+
"long"
137+
]
131138
}
132139
}
133140
}

source/connection-monitoring-and-pooling/tests/logging/connection-pool-options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ tests:
7171
driverConnectionId: { $$type: [int, long] }
7272
serverHost: { $$type: string }
7373
serverPort: { $$type: [int, long] }
74+
durationMS: { $$type: [double, int, long] }
7475

7576
# Drivers who have not done DRIVERS-1943 will need to skip this test.
7677
- description: "maxConnecting should be included in connection pool created message when specified"

0 commit comments

Comments
 (0)