[CSHARP-1947] Subscription to cluster events leads to new connection pool created Created: 19/Mar/17 Updated: 27/Oct/23 Resolved: 28/Apr/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Configuration |
| Affects Version/s: | 2.4.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | sergii | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I am working on Web API project that should be hosted on azure environment. I would like to log commands execution time and details per web request. To make it possible I subscribe to CommandStartedEvent, CommandSucceededEvent and CommandFailedEvent events that give me all necessary information. But as I should link mongo command to web request I have to create new MongoClient per web request and subscribe to events for every new MongoClient. As result mongo driver create new connection pool for every new MongoClient. On Azure environment amount of opened tcp connections is limited so my application start to response with mongo timeout exception just after few second being under load. |
| Comments |
| Comment by Robert Stam [ 28/Apr/17 ] |
|
You would have to use some mechanism outside of the driver to correlate driver events to web requests. You could look into .NET classes like:
to find ways of correlating driver events to web requests. |
| Comment by sergii [ 20/Mar/17 ] |
|
Thank you for response.
|
| Comment by Robert Stam [ 20/Mar/17 ] |
|
The intent is that all MongoClient instances that have the same settings should share a single underlying connection pool. For some data types determining whether two values are equal is difficult, as is the case with the ClusterConfigurator property of MongoClientSettings. This can lead to multiple connection pools being created when only one is desired. Your simplest approach is to only create a single instance of MongoClient and use this single instance for all your web requests. MongoClient is thread-safe and can be safely used by multiple web requests at the same time. |