note 107544 deleted from mongo.construct by bjori

From: Date: Sun, 02 Sep 2012 12:18:02 +0000
Subject: note 107544 deleted from mongo.construct by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190415@lists.php.net to get a copy of this message
Note Submitter: Niek at sourcebox dot nl ---- After a big crash on our mongo database replica-set we started to investigate why PHP hangs itself when a server seems to disappear. It seems that this library isn't doing a very good job with connecting to a replicate set. In the official mongo manual it says: "The driver then connects to all servers on the seed list, perhaps in parallel to minimize connect time .." PHP doesn't do parallel. It tries every seed from the list one at the time. After one fails it goes to the next etc. This is how PHP works and i doubt it can be altered. So the problem starts when you connect like: new Mongo("mongodb://192.168.0.100,192.168.0.101", array("replicaSet" => "myReplicaSet")); When the server 192.168.0.100 crashes, all new connections will take at least 20 seconds (20 seconds connection timeout) before it moves to the second server. The webserver will come crashing down with all these hanging PHP instances. (If the server is still up though only the mongo service is down everything does continue to work without the delay though.) The timeout setting will remedy a bit of this behavior making the connection like: (100 ms timeout) new Mongo("mongodb://192.168.0.100,192.168.0.101", array("replicaSet" => "myReplicaSet", "timeout" => 100)); All new connections have a additional delay of 100 ms when there is a server crash which is better then the 20000 ms default value. Still not perfect but workable. This behavior isn't really excepted when reading the manuals and people may think they have an failover mongo. This isn't the case when you are not using the timeout property.

« previous php.notes (#190415) next »