Does anyone have any prior experience of working with the MongoDB C# Driver (v2+) with singleton style connection/collection instances in terms of connection resilience?
The Problem
We have recently made a push to secure our wider infrastructure, essentially running everything over SSL even internally. As such we recently secured one of our primary MongoDb clusters. One of the most immediate differences was the increase in cost of connecting to the cluster. Our old solution followed a typical repository pattern whereby a subscriber to a message would instantiate the repository and also new up a connection before allowing it be GCd after the processing of that message. We saw a pretty major drop in message processing performance as a result of switching to SSL - more than we'd honestly expected!
The Question(s)
Is there a recommended way to work with IMongoClient
, IMongoDatabase
, IMongoCollection<T>
with respect to long-lifetime instances (weeks/months). Does it gracefully handle..
- Specific nodes going down within the cluster (but the cluster remaining available)
- The entire cluster going offline (e.g. major network outage)
- Would setting larger timeouts etc. be wise and what's the impact?
My current understanding is that 1. should be no problem, for 2. it attempts to buffer operations within the timeout window and process them once the cluster is available again. 3. depends largely on memory and timeliness of the operation (something we'll need to think about internally).
If the cluster is down longer than the various timeouts allow I'm assuming an exception is thrown at which point I'm also assuming that my instance(s) would become useless unless I can tell the driver to retry connecting to the cluster indefinitely. To me this appears to be the grey area when it comes to documentation and my own research - can anyone offer more reading material or suggestions for ways to cope with network faults etc for this sort of scenario?
Many thanks in advance,