0

我们有一个带有 2 个节点的 Mongodb 副本集,每个节点位于不同国家的不同 CPD 中。

两个节点之间的延迟是可测量的。写入数据时这不是问题,因为这是使用离线进程每天完成一次。

但是在读取的时候,每个请求中的节点都会建立它们之间的连接,这会花费很多时间并且使请求变慢,并且会在网络上产生问题。

我们发现在主节点和辅助节点之间打开了大约 700 个连接。

我尝试了几种连接、连接字符串和 readPreference 设置,但这总是会发生。

有没有什么方法可以在每个请求的节点之间不进行连接?当节点之间的距离不是很近时,人们如何应对这个问题?

编辑:

如果我重复运行测试脚本,有时它会非常快。我在 MongoLog 详细信息中看到了这一点:

180 [+0.004990] IO FINE getting cursor body
181 [+0.005032] CON FINE No timeout changes for xxxx:27017;rs1;.;101877
182 [+0.005080] CON FINE Initializing cursor timeout to 30000 (from connection options)
183 [+0.005095] CON INFO command supports Read Preferences
184 [+0.005109] CON INFO mongo_get_read_write_connection: finding a REPLSET connection (read)
185 [+0.005128] CON FINE found connection xxxxx:27017;rs1;.;101877 (looking for xxxx:27017;rs1;.;101877)
186 [+0.005140] CON FINE is_ping: skipping: last ran at 1432113918, now: 1432113922, time left: 1
187 [+0.005153] CON FINE found connection yyyy:27017;rs1;.;101877 (looking for yyyyy:27017;rs1;.;101877)
188 [+0.005163] CON FINE is_ping: skipping: last ran at 1432113919, now: 1432113922, time left: 2
189 [+0.005175] CON FINE discover_topology: checking ismaster for xxxxx:27017;rs1;.;101877
190 [+0.005186] CON FINE found connection xxxx:27017;rs1;.;101877 (looking for xxxxx:27017;rs1;.;101877)
191 [+0.005196] CON FINE ismaster: skipping: last ran at 1432113919, now: 1432113922, time left: 12
192 [+0.005206] CON FINE discover_topology: ismaster got skipped
193 [+0.005218] CON FINE discover_topology: checking ismaster for yyyyy:27017;rs1;.;101877
194 [+0.005228] CON FINE found connection yyyyy:27017;rs1;.;101877 (looking for yyyyy:27017;rs1;.;101877)
195 [+0.005237] CON FINE ismaster: skipping: last ran at 1432113919, now: 1432113922, time left: 12
196 [+0.005246] CON FINE discover_topology: ismaster got skipped

当 3 个计时器中的任何一个达到 0 时,连接就建立了。看起来我可以增加 3 次检查的间隔,对吧?

4

1 回答 1

0

我最终通过进行这些更改来解决问题:

  • mongo.is_master_interval将和设置更改mongo.ping_interval为更高的值
  • 更改读取和写入操作的连接设置。对于阅读,我使用独立的连接配置(没有replicaSet 参数),对于写入,使用replicaSet 配置。这样,读取操作不会在服务器之间产生连接。
于 2015-05-21T07:04:57.567 回答