Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb and php: connection pooling

I'm using the native driver in PHP to connect to a mongo DB.

I don't understand the concept of connection pooling: is this like a 'pool' of connections, and when a user opens the website, a connection is pulled from this pool and used?

But what if you have multiple pages with some code that uses a mongoDB? Will the system pull a new connection from the pool every time the user changes the page?

In general: how can I manage this 'connection pool' (or is it managed automatically) when there are a lot of simultaneous connections?

like image 914
Sam Leurs Avatar asked Jan 21 '12 18:01

Sam Leurs


1 Answers

I don't understand the concept of connection pooling: is this like a 'pool' of connections, and when a user opens the website, a connection is pulled from this pool and used?

Yes, that's exactly what it is.

But what if you have multiple pages with some code that uses a mongoDB? Will the system pull a new connection from the pool every time the user changes the page?

Yes. The connection is taken from the pool when required (a user loads a page), and then returned to the pool when the script ends. It is persistent by default (set via the mongo.allow_persistent php.ini setting) and automatically handled by the driver.

In general: how can I manage this 'connection pool' (or is it managed automatically) when there are a lot of simultaneous connections?

Connection pools are mostly managed automatically. You have some level of control using the MongoPool class.

like image 126
netcoder Avatar answered Sep 27 '22 16:09

netcoder