我遇到连接副本集的问题(4 db + 1仲裁)。
基准:
<?php
echo "rp: nearest" . PHP_EOL;
$m = new MongoClient("mongodb://app1.n.prod,app1.m.prod,app2.m.prod,app1.d.prod/?replicaSet=booklet&readPreference=nearest&readPreferenceTags=dc:nsk");
echo "rp: primary" . PHP_EOL;
$m = new MongoClient("mongodb://app1.n.prod,app1.m.prod,app2.m.prod,app1.d.prod/?replicaSet=booklet&readPreference=primary");
echo "rp: secondary" . PHP_EOL;
$m = new MongoClient("mongodb://app1.n.prod,app1.m.prod,app2.m.prod,app1.d.prod/?replicaSet=booklet&readPreference=secondary");
echo "localhost, rs" . PHP_EOL;
$m = new MongoClient("mongodb://localhost/?replicaSet=booklet");
echo "rp: secondary, without rs" . PHP_EOL;
$m = new MongoClient("mongodb://app1.n.prod,app1.m.prod,app2.m.prod,app1.d.prod/?readPreference=secondary");
echo "localhost, without rs" . PHP_EOL;
$m = new MongoClient("mongodb://localhost");
结果(php microtime中的时间(true)):
rp: nearest 1422547256.97 1422547258.8778 rp: primary 1422547258.8778 1422547259.7998 rp: secondary 1422547259.7999 1422547260.7213 localhost, rs 1422547260.7213 1422547260.7223 rp: secondary, without rs 1422547260.7223 1422547261.4674 localhost, without rs 1422547261.4674 1422547261.4683
为什么连接到副本集需要这么长时间? (每个连接1秒)
答案 0 :(得分:0)
尝试使用ip而不是域名:
$m = new MongoClient("mongodb://10.10.0.100:27017,10.10.0.101:27017,10.10.0.102:27017/?replicaSet=booklet&readPreference=nearest&readPreferenceTags=dc:nsk");