0

I have a problem with connecting to replica set (4 db + 1 arbiter).

Benchmark:

<?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");

Results (time in 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

Why does connecting to replica set take so long? (1 second per connection)

Mobyman
  • 121
  • 4
  • It would be helpful if you provided some additional log info from [MongoLog](http://php.net/manual/en/class.mongolog.php), as that reports internal driver activity for establishing connections to replica sets (among many other things). By default, it will emit PHP notices, but you can customize the logging via [MongoLog::setCallback()](http://php.net/manual/en/mongolog.setcallback.php). Having your callback also log a timestamp before each message would let us calculate the delay between each event. – jmikola Feb 03 '15 at 17:09

1 Answers1

0

Try using ip instead domain name:

$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");
debug
  • 1
  • 2