因此,当我连接到具有多个主机的MongoDB时,执行命令时每1分钟会有一个延迟。延迟时间正好是10秒。我知道这听起来很奇怪。
首先,我认为问题与MongoDB服务器配置有关。但这只会在我使用PHP mongodb驱动程序时发生,因为在使用Java mongodb驱动程序进行测试时,它可以正常工作。 -MongoDB服务器:3.6 -PHP mongodb驱动程序:1.5.3 -Java mongodb驱动程序:3.10.1
我也用同样的问题测试了旧版本的PHP mongodb驱动程序。
PHP
// start tracking reading time
$start = microtime(true);
$m = new \MongoDB\Client('mongodb://rs1.host.com,rs2.host.com');
$db = $m->selectDatabase('test');
// slow when querying
$db->selectCollection('user')->findOne();
// end tracking reading time
$end = microtime(true);
$duration = $end - $start;
完整的源代码:https://drive.google.com/open?id=1r-EKiCntZbUq59sFzaBOiCrfy0tzjadt
Java
Date date1 = new Date();
long start = date1.getTime();
MongoClient mongoClient = MongoClients.create("mongodb://rs1.host.com,rs2.host.com");
MongoDatabase db = mongoClient.getDatabase("ple");
db.getCollection("user").find().first();
Date date2 = new Date();
long end = date2.getTime();
System.out.println((end - start) + "ms");
完整的源代码:https://drive.google.com/open?id=1TYTFrRxUiQUZdIUJdetllHpnOYHQiepd
我每2秒重复一次上面的脚本,所以这是我测试的结果:
PHP
0.013s
0.0056s
0.0135s
0.0052s
10.0271s (54sec from last delay)
0.0057s
0.0059s
0.0122s
0.0108s
0.0106s
0.0133s
0.014s
0.0095s
0.0076s
0.0145s
0.0102s
0.0148s
0.0058s
0.0132s
0.0125s
0.0134s
0.0056s
0.0055s
0.0135s
0.0124s
0.0116s
0.013s
0.013s
0.0139s
0.0135s
0.0132s
10.0234s (52sec from last delay)
0.0125s
0.0128s
0.0168s
0.0121s
0.0131s
0.0134s
0.0141s
0.0128s
0.0128s
0.0123s
0.0131s
0.0156s
0.006s
0.0053s
0.0058s
0.0136s
0.0131s
0.0139s
0.0131s
0.0063s
0.0125s
0.0127s
0.013s
0.0061s
0.0058s
10.015s (52sec from last delay)
0.0071s
0.0144s
Java
16ms
17ms
17ms
16ms
19ms
17ms
16ms
17ms
16ms
17ms
17ms
16ms
17ms
16ms
16ms
16ms
16ms
17ms
16ms
15ms
17ms
17ms
15ms
17ms
16ms
17ms
16ms
15ms
16ms
17ms
15ms
17ms
16ms
16ms
14ms
18ms
16ms
15ms
17ms
16ms
15ms
17ms
17ms
16ms
16ms
17ms
16ms
20ms
16ms
16ms
19ms
15ms
15ms
17ms
16ms
16ms
16ms
15ms
15ms
17ms
16ms
17ms
16ms
15ms
16ms
18ms
15ms
17ms
18ms
15ms
15ms
17ms
16ms
16ms
16ms
15ms
16ms
16ms
17ms
16ms
17ms
17ms
15ms
16ms
16ms
14ms
16ms
17ms
16ms
15ms
17ms
17ms
15ms
有人知道PHP mongodb驱动程序有什么问题吗?
答案 0 :(得分:2)
我遇到了完全相同的情况,在我们的案例中,这是因为PHP客户端无法到达仲裁者,即使我们在任何地方都没有提到它。 通过打开仲裁服务器上的客户端防火墙,我们解决了这种情况。