ursitesion
ursitesion

Reputation: 988

What is connection pooling in an application?

A framework or an application automatically connect the database and we have to just use the database object for DB related operation. In CMS or framework, a term "connection pooling" is very popular. You can opt CMS or framework of PHP.

Upvotes: 1

Views: 262

Answers (2)

deceze
deceze

Reputation: 522005

Connection pooling generally refers to, well, having a pool of connections which is being reused. To contrast this with non-pooled connections: typically every program instance connects to the database by itself every time it is run. In a PHP program, you just have the line $db = new PDO(...), which connects to the database. If you have 100 simultaneous visitors, 100 separate instances of that script will be run simultaneously, and 100 separate connections will be established to the database simultaneously. This may be very inefficient and/or temporarily overwhelm the database server.

A connection pool works by establishing, say, 50 permanent connections to the database which stay open the whole time. A PHP script would then simply pick one of these open connections to talk to the database and drop it back into the pool when it's done. If suddenly more than 50 PHP scripts try to use connections from this pool at once, the first 50 will succeed, and the rest will have to wait in line until an unused connection becomes available. This is more efficient, because connections aren't opened and torn down all the time, and it doesn't overwhelm the database server when sudden spikes occur.

Upvotes: 3

Quentin
Quentin

Reputation: 943142

Without connection pooling:

Every time you want to talk to the database, you have to open a connection, use it, then close it again.

With connection pooling:

The connections are kept open all the time (in a pool). When you want to talk to the database, you take an already connection, that isn't already in a use, use it, then put it back.

This is more efficient then opening and closing them all the time.

Upvotes: 6

Related Questions