Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB and Multiple C# Client Threads

I have a single primary instance of a MongoDB to connect to. I am using the C# driver (latest revision) to connect and utilise MongoDB.

My client application is multi-threaded whereby processes will run periodically at different intervals to produce reports. When more than one thread is running, and I call various functions on the driver (e.g server.DatabaseExists(...)), I am consistently met with an exception.

"The requested name is valid, but no data of the requested type was found"

 at System.Net.Dns.GetAddrInfo(String name)
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at MongoDB.Driver.MongoServerAddress.ToIPEndPoint(AddressFamily addressFamily) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoServerAddress.cs:line 195
   at MongoDB.Driver.MongoServerInstance.GetIPEndPoint() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 339
   at MongoDB.Driver.Internal.MongoConnection.Open() in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 368
   at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream() in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 574
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode, String databaseName) in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 555
   at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 295
   at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 253
   at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 141
   at MongoDB.Driver.MongoDatabase.GetCollectionNames() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 645
   at MongoDB.Driver.MongoDatabase.CollectionExists(String collectionName) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 297

Running one thread does not cause this issue. I am of the understanding that MongoDB is thread-safe, so I am at loss to understand the cause and the remedy.

like image 834
Jason Avatar asked Oct 31 '12 02:10

Jason


People also ask

Is MongoDB multithreaded?

The MongoDB server currently uses a thread per connection plus a number of internal threads. You can list all threads (including idle and system) using db. currentOp(true) in the mongo shell. If you have 8 incoming requests, each of those will be handled by a separate connection thread.

Can a MongoDB have multiple collections?

Each MongoDB collection can have multiple documents. A document is equilant to row in a table in RDBMS. To create a collection, use the db. createCollection() command.

Does MongoDB support strong consistency?

By default, MongoDB is a strongly consistent system. Once a write completes, any subsequent read will return the most recent value. Cassandra, by default, is an eventually consistent system. Once a write completes, the latest data eventually becomes available provided no subsequent changes are made.

Can MongoDB have many to many relationship?

Many to Many relationships are a type of mongodb relationship in which any two entities within a document can have multiple relationships. In this relationship, we can consider a case of Online courses website where there are many courses and also many users.


1 Answers

The only "solution" I've found was to recycle the Application Pool that's hosting my website\service calling the mongo client.

like image 174
arviman Avatar answered Sep 19 '22 16:09

arviman