Why use a database connection pool?
Options
- To encrypt the queries that are sent from the app to the database
- Opening connections is costly; a pool reuses a limited set of them (Correct option)
- To split the data of the application across several servers
- To cache the results of queries that are repeated often
Answer
Opening connections is expensive; a pool reuses a bounded set and protects the DB from too many connections
Why
Opening a database connection takes time (network handshake, authentication) and each open connection uses memory on the database server.
A pool keeps a fixed number of connections open and lends them to requests, which return them when done.
Size it so that all app instances together stay under the database's max connections.
Remember
Reuse connections with a pool; don't open one per query.