MongoDB:使用CompositeServerSelector选择服务器30000ms之后发生超时 [英] MongoDB: A timeout occured after 30000ms selecting a server using CompositeServerSelector

查看:85
本文介绍了MongoDB:使用CompositeServerSelector选择服务器30000ms之后发生超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全迷住了.我正在使用最新的c#驱动程序(2.3.0.157)和最新的MongoDB(3.2).数据库作为独立安装程序运行,没有复制或分片.我试过在Windows上本地运行以及在Amazon LINUX上远程运行.

I'm completely stumped. I am using the latest c# drivers (2.3.0.157) and the latest MongoDB (3.2). The DB is running as a standalone setup with no replication or sharding. I've tried running locally on Windows as well as remotely on Amazon LINUX.

我仍然会遇到超时错误,但有时它神秘地起作用了(也许每20-30次尝试一次).

I continue to get a timeout error but mysteriously sometimes it just works (maybe once every 20 - 30 attempts).

我正在这样创建连接:

private static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ToString();
private static readonly string DataBase = ConfigurationManager.ConnectionStrings["MongoDBDatabase"].ToString();

private static IMongoDatabase _database;


public static IMongoDatabase GetDatabase(string database)
{
    if (_database == null)
    {
        var client = new MongoClient(ConnectionString);
        _database = client.GetDatabase(database);

    }

    return _database;
}

并这样称呼它:

public static List<Earnings> GetEarnings()
{
    var db = GetDatabase(DataBase);
    if (db == null) return new List<Earnings>();
    var logs = db.GetCollection<Earnings>("EarningsData");
    var all = logs.Find(new BsonDocument()).ToEnumerable().OrderBy(x => x.Symbol).ToList();
    return all;
}

它将在日志上超时.查找方法的一部分.这是完整的消息:

And it'll time out on the logs.Find part of the method. Here's the full message:

其他信息:

使用CompositeServerSelector {Selectors = ReadPreferenceServerSelector {ReadPreference = {Mode = Primary,TagSets = []}},LatencyLimitingServerSelector {AllowedLatencyRange = 00:00:00.0150000}}选择服务器30000ms之后,发生超时.群集状态的客户端视图为{ClusterId:"1",ConnectionMode:"Direct",类型:"Unknown",状态:"Disconnected",服务器:[{ServerId:"{ClusterId:1,EndPoint:" XX.XX. XX.XX:27017}",端点:"XX.XX.XX.XX:27017",状态:"Disconnected",类型:"Unknown"}]}.

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = [] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Direct", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "XX.XX.XX.XX:27017" }", EndPoint: "XX.XX.XX.XX:27017", State: "Disconnected", Type: "Unknown" }] }.

我尝试使用完全限定的主机名,将MongoClientSettings而不是连接字符串以及连接符添加到连接字符串中,而connect = direct和connect = replicaSet可以在论坛和StackOverflow上找到.我很茫然,甚至不知道下一步该怎么看.有什么建议吗?

I've tried using the fully qualified host name, adding connect=direct and connect=replicaSet to the connection string, using MongoClientSettings instead of the connection string and everything else I could possibly find on forums and StackOverflow. I'm at a loss and not even sure where to look next. Any advice?

我还应该添加,我可以从命令行和RoboMongo进行正常连接...

I should also add, I can connect fine from the command line and RoboMongo...

推荐答案

我们终于想出了解决此问题的方法,但我仍然不知道发生了什么.在我们的例子中,我们有一台服务器,该服务器产生约10个信号中心,这些信号中心从MongoDB获取数据.看来,在应用程序启动时,它正在快速调用MongoDB以获取初始数据集,尽管偶尔会起作用,但大多数时候却没有.最后,我们在加载每个SignalR集线器之间增加了一秒钟的延迟,从而解决了这一问题,因此初始查询被延迟了一点,而且我们没有争用.

We finally figured out how to work around this issue but I still don't understand what's happening. In our case, we have a server that spawns ~10 signalr hubs that get their data from MongoDB. It seems that when the app was starting up it was making several rapid calls to MongoDB to get the initial set of data and while it would occasionally worked, most times it didn't. We ended up solving this by adding a one second delay between loading each SignalR hub so the initial query was delayed a bit and we didn't have contention.

奇怪的是,这些集合中没有一个拥有大量数据,初始负载通常为<每次收集100个文件(最多).一旦事情初始化了,我们点击MongoDB的频率似乎并不重要.它似乎只是在初始负载上.

The weird thing about this is none of these collections have a large amount of data and the initial load is usually < 100 documents per collection (max). Once things are initialized it doesn't seem to matter how often we hit MongoDB. It just seems to be on the initial load.

这篇关于MongoDB:使用CompositeServerSelector选择服务器30000ms之后发生超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆