[CSHARP-1825] Timeout waiting for connection Created: 14/Nov/16 Updated: 05/Apr/19 Resolved: 07/Feb/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Connectivity |
| Affects Version/s: | 2.3 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Critical - P2 |
| Reporter: | Chirag Patel | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows server 2012 R2 |
||
| Description |
|
When calling InsertOneAsync on IMongoCollection<T>, I am getting following exception. Here is what my code looks like. Since I don't need to wait for document to be inserted, I call InsertOneAsync and return. This Insert method is rapidly called multiple times. public class MyClass{ public void InsertData(T data) { myColl..InsertOneAsync(data); }... Exception Details: 2016-11-14 10:44:30,346 [30] ERROR - ERROR: Failed to process item. Timed out waiting for a connection after 120484ms. |
| Comments |
| Comment by Robert Stam [ 14/Nov/16 ] |
|
You could use the size of the connection pool as a guide. As mentioned above the default connection pool size is 100. That means that at most 100 database operations can be in flight at the same time. So you could throttle your application to ensure that no more than 100 database operations are in flight at the same time. And if you want more than 100 database operations in flight at the same time you can increase the size of the connection pool, either on the connection string or in MongoClientSettings. https://docs.mongodb.com/manual/reference/connection-string/ |
| Comment by Chirag Patel [ 14/Nov/16 ] |
|
My application has a queue and a single thread dequeues single item from queue and inserts into MongoDB using InsertOneAsync. I'd like to throttle my application, however I don't know any parameters from MongoDB driver to throttle my app. Are there any methods or properties available on driver that can help me throttle my app? |
| Comment by Robert Stam [ 14/Nov/16 ] |
|
I think you are just trying to do too many things at one. The connection pool settings default to having 100 connections and to allowing up to 500 tasks to be waiting for a connection to be come available. That means you can have at most 600 tasks in flight at the same time (100 using a connection and 500 more waiting for a connection). If you are rapidly firing off InsertOneAsync tasks and not waiting for the response you are probably exceeding the 600 limit. You can increase the limits by configuring the connection pool to have more connections or increasing the size of the connection pool's wait queue. A more robust solution would be to throttle your application somehow (for example, limit the number of concurrent tasks to 600). |