In software engineering, a connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools are used to enhance the performance of executing commands on a database. Opening and maintaining a database connection for each user, especially requests made to a dynamic database-driven website application, is costly and wastes resources.
- Performance. Connecting to the database is expensive and slow. Pooled connections can be left physically connected to the database, and shared among the various components that need database access. That way the connection cost is paid for once and amortized across all the consuming components.Creating prepared statements is also expensive for some drivers, and the connection pool can cache statements for a connections across requests
- Diagnostics. If you have one sub-system responsible for connecting to the database, it becomes easier to diagnose and analyze database connection usage.
- Maintainability. Again, if you have one sub-system responsible for handing out database connections, your code will be easier to maintain than if each component connected to the database itself. Also maintaining many idle connections is expensive for a database management system, and the pool can optimize the usage of idle connections (or disconnect if there are no requests).