使用Async API从mongo c#驱动程序中获取TimeoutExceptions

时间:2015-02-25 15:42:25

标签: mongodb mongodb-.net-driver

我们正在使用MongoDB(2.0.0-beta2)的最新beta驱动程序以及所有异步功能。但是与旧的实现(1.10.0-rc0)相比,我们得到了一些奇怪的TimeoutExceptions。我们尝试过不同的服务器版本(其中包括3.0.0-rc10),但这似乎并没有影响到它。

System.TimeoutException occurred
  HResult=-2146233083
  Message=Operation timed out after 00:00:30.
  Source=MongoDB.Driver
  StackTrace:
       at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__0`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperation>d__5e`1.MoveNext()

我们很难重现这一点,发射数千个插入,更新和查找不会触发此错误。但是,运行我们的.NET Web应用程序会触发此操作(在创建几个新实体之后)。

异常位置不同,但其中一个位置在我们的FindAll方法中。我们的代码确实:

IMongoCollection<BsonDocument> col = _database.GetCollection<BsonDocument>(GetCollectionName(qmoType));
IFindFluent<BsonDocument, BsonDocument> findFluent = col.Find(MongoDBWhereBuilder.BuildWhere(where));

findFluent = findFluent.Sort(SortBy.Ascending(sort.Keys.ToArray());
findFluent = findFluent.Skip(skip);
findFluent = findFluent.Limit(take);

List<BsonDocument> list = await findFluent.ToListAsync();

_database变量在所有请求之间共享(在启动时创建一次)。

我们怎样才能更好地掌握这个问题?还是有其他人有这个问题吗?

2 个答案:

答案 0 :(得分:1)

这是beta2驱动程序中的错误。修复程序合并为master(和beta3的一部分):https://jira.mongodb.org/browse/CSHARP-1184

答案 1 :(得分:0)

我认为版本2.0.1 / 2.1.0中可能仍然存在。我们不得不降级到1.10.0这是我们之前的版本,这使得连接数回到100以下,响应时间减少到100ms(有时从500-600)。

在异步代码的遗留包装器中可能存在导致延迟的内容。