Background:
Opening a database connection is a resource intensive
and time consuming operation. Connection pooling is a boon to performance since
it increases the performance by reusing the database connection instead of
creating a new connection for every request.
So what is a connection pool and how does it work?
It is a pool of open database connections. When
a new connection request comes in, the pool manager checks if the pool contains
any unused connections and returns one if available. If all the connections
in the pool are busy and the maximum size has not been reached, a new connection is created and added to the pool. When the pool reaches its maximum
size, the connection requests will be being queued up until a connection in the
pool becomes available or the connection will be times out.
Parameters of a connection pool
There are 4 parameters that control the behavior
if a connection pool
- Connect timeout
It controls the wait period when a new
connection is requested. If this timeout
expires, an exception will be thrown.
- Min pool size
Initial number of connections that will be added
to the pool. Say if you set it to 5, there will be 5 connections available
readily to server the requests. So the user requests won’t have to wait for the
database connection to establish.
- Max pool size
It is the maximum size that a connection pool
can grow. If you set it to 100, the
connection pool will grow from the min size to the max size based on the user
requests. After it reached the max size, the requests will start queued up.
- Pooling
It lets you to control if you want to sue the
connection pooling or not. It is controlled by the key words true or false based
on your requirement.
What is a connection leak?
When the application doesn't close the database connection
correctly and consistently, it is called as connection leaks. Eventually you
will be thrown with some kind of exception or connection failures.
Fix for connection leaks
Ensure that the database connections are always
closed in your code.


No comments:
Post a Comment