Details
-
Improvement
-
Resolution: Gone away
-
Major - P3
-
None
-
None
-
None
-
None
-
(copied to CRM)
Description
We recently updated from mongodb server 4.2 / mongodb driver 2.12.5 to mongodb server 5.0 / mongodb driver 2.17.0, after which we have observed a rise in timeouts from our applications, and a sawtooth-shape in our open connections graph. (We use an EventSubscriber to keep track of open connections.)
After some investigation, we see that there is a significant change in how connections are maintained in the ExclusiveConnectionPool.
v2.12.5 would prune 1 connection at a time (note the break statement in the loop):
https://github.com/mongodb/mongo-csharp-driver/blob/v2.12.5/src/MongoDB.Driver.Core/Core/ConnectionPools/ExclusiveConnectionPool.cs#L818
whilst newer versions will quite aggressively remove all expired connections:
This is a problem for our applications, which require many open connections (100) at all time. (Our applications handle high spikes of traffic, with quiet periods in between.)
During quiet periods, MaintenanceHelper (v2.17.0) will periodically remove all existing connections, and spend some time creating new ones. When a traffic spike hits our application at the same time, the application will not be able to serve incoming requests, and we get lots of timeouts.
v2.12.5 of the driver would remove one connection, open one connection, remove one, open one etc, which results in the application always having available open connections.
v2.17.0 removes all connections at once, which renders our application useless for the next (15-30) seconds.
We rely on MaintenanceHelper maintaining connections "the old way", or we cannot use the driver.