I have a mongodb server in production serving on an EC2 instance. According to the mongodb official documentation, persistent DB connections should ALWAYS be used in production. I’ve been experimenting with about 50 persistent connections and was getting frequent connection errors (approx 33% of the time) while testing. I’m using this code:
$pid = 'db_'.rand(1,50);
$mongo = new Mongo("mongodb://{$user}:{$pass}@{$host}", array('persist' => $pid) );
Some background on the application, it’s a link tracking application that is still ramping up – and is in the range of 500 – 1k writes per hour, nothing too crazy… yet.
I’m wondering if I simply need to allow more persistent connections? How does one determine the right balance of persistent connections versus server resources available?
Thanks in advance everyone.
The
persistvalue is no longer supported as of the most recent driver (1.2.0).Truth is, it was never really clear what it did in typical Apache+PHP setups. There are several comments on the Google Groups and elsewhere asking for detail, but I did not any evidence that
persistorpersistentwas ever tested with any depth.Instead, it’s all been replaced by connection pooling “out of the box”. The connection pooling has obviously been through some changes within the 1.2 line with the addition of the MongoPool class.
There is still no detailed explanation of how the pooling works with Apache, but at least you don’t have to worry about
persist.Now despite all of this mess, I have handled 1000 times that traffic on a single MongoDB server via the PHP driver without lots of connection problems.
Are you catching the exceptions?
Can you provide more details about the exact exception?
There may be a code solution.