Hi Mukesh,
Since PHP MongoDB driver v1.3.0 (current stable version is v1.6.12), persistent connections are used to minimise the number of connections made to each database server. These connections are saved by the PHP worker process and may be reused between multiple requests.
See blog: mongodb php driver connections handling for more info.
We want to set connection pool at server level.
Could you elaborate more on what do you mean by server level ?
Note that a connection normally would consists of host, port, process id, (if any) replica set name, or (if any) authentication credentials, etc.
When our no of connection reach to 400, our db performance impact so badly, and query time increase up to 4 times.
Other than the number connections, you should also check what those connections are doing. You should check the active working set of your MongoDB deployment whether it fits in RAM or not.
Use mongostat to find out a quick overview of your mongod status. See mongostat fields to find out their meanings.
Can you provide the following information:
Kind regards,
Wan.
Hi Suvarna,
For MongoDB C driver connection pooling please see mongoc_client_pool_t for a thread-safe pooling example.
If you still have further questions, please open a new thread discussion detailing:
Kind regards,
Wan.
Code snippet that creates connection- Laravel manage connections to mongo.
Hi Mukesh,
There are a number of factors that may affect the number of connections from your usage of Laravel. i.e. number of object models and the code interacting with them, relationships between the object models and query operations, life cycle of the object models, laravel configs, etc.
As a start I would suggest to check out persistent database connections. You should test with and without the persistent connections and see whether you can tweak the number of connections down.
/* For example specify in config/database.php */
'options' => array(
PDO::ATTR_PERSISTENT => true,
)
See Laravel PDO connection options for an example how to use PDO connections. Generally it is better to share the connection through your application.
If you have further questions on Laravel connection pooling behaviour, you may get faster responses by posting a question on StackOverflow or Laravel Forum.
Total no of instances are 12.
Other than keeping the number of connections low, also check what the connections are being used for. For example you can :
Also see Analyzing MongoDB performance for more info.
As previously mentioned, you may also want to check the database working set. As you may need to scale up either vertically and/or horizontally for your current application demands.
Regards,
Wan.
Hi Mukesh,
Correction regarding the PDO option part:
PDO is distinct from the MongoDB PHP driver and only applies to SQL drivers.
As previously mentioned, the PHP MongoDB driver already uses persistent connections by design since v1.3.0. Unless your code is manually closing connections via MongoClient::close() - which generally is not recommended, you should expect one socket to each mongod (in the case of a replica set) per PHP process (e.g. Apache worker if PHP is a module, or FPM worker if you’re using FastCGI with something like nginx or Apache).
If you have further questions on the use of Laravel, you may get faster responses and wider audience by posting a question on StackOverflow or Laravel Forum.
Regards,
Wan.