我们最近将我们的Web应用程序升级到MongoDB C#Driver 2.0并部署到生产中.低于一定负载,应用程序运行正常.一旦生产服务器上的负载超过某个限制,应用程序的CPU立即降至0,大约30秒后,将多次记录此异常:
System.TimeoutException message: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = System.Collections.Generic.List`1[MongoDB.Driver.TagSet] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", Type : "Standalone", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/10.4.0.113:27017" }", EndPoint: "Unspecified/10.4.0.113:27017", State: "Disconnected", Type: "Unknown" }] }.
stack trace:
at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
at MongoDB.Driver.Core.Clusters.Cluster.<WaitForDescriptionChangedAsync>d__18.MoveNext() …
Run Code Online (Sandbox Code Playgroud) .Net 控制台应用程序在 4.6.1 框架中,使用 MongoDB.Driver 2.8.0。我在 SO 中引用了许多帖子,但我仍然收到超时错误。下面是我参考的一些帖子
使用 CompositeServerSelector System.TimeoutException 选择服务器 30000 毫秒后发生超时:使用 CompositeServerSelector MongoDB C# 2.0 TimeoutException选择服务器 30000 毫秒后发生超时
下面是我用来从集合中访问文档的代码。
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
class Program
{
static void Main(string[] args)
{
string connectionString =
@"mongodb://mongoaccnt:ADASDXZWADAS2VgsqTYcTS4gtADmB1zQ==@mongocnt.documents.azure.com:10255/?ssl=true&replicaSet=globaldb";
MongoClientSettings settings = MongoClientSettings.FromUrl(
new MongoUrl(connectionString)
);
settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
var mongoClient = new MongoClient(settings);
string dbName = "app-db";
string collectionName = "test";
var database = mongoClient.GetDatabase(dbName);
var todoTaskCollection = database.GetCollection<test>(collectionName);
var filter …
Run Code Online (Sandbox Code Playgroud)