9 Connection Pool Manager : Configuring the Connection Pool

Configuring the Connection Pool
You can configure attributes of a connection pool for optimal performance and scalability using the methods provided by the DataDirect Connection Pool Manager classes (see “DataDirect Connection Pool Manager Interfaces”).
Some commonly set connection pool attributes include:
■
■
■
■
See “Understanding the Maximum Pool Size” for more information about how the Pool Manager implements the maximum pool size. In addition, the Pool Manager implements minimum pool size, maximum pool size, and initial pool size differently depending on whether reauthentication is enabled. See “Using Reauthentication with the Pool Manager” for details.
Understanding the Maximum Pool Size
You set the maximum pool size using the PooledConnectionDataSource.setMaxPoolSize() method. For example, the following code sets the maximum pool size to 10:
ds.setMaxPoolSize(10);
You can control how the Pool Manager implements the maximum pool size by setting the PooledConnectionDataSource.setMaxPoolSizeBehavior() method:
■
If setMaxPoolSizeBehavior(softCap), the number of active connections can exceed the maximum pool size, but the number of idle connections for each user in the pool cannot exceed this limit. If a user requests a connection and an idle connection is unavailable, the Pool Manager creates a new connection for that user. When the connection is no longer needed, it is returned to the pool. If the number of idle connections exceeds the maximum pool size, the Pool Manager closes idle connections to enforce the pool size limit. This is the default behavior.
■
If setMaxPoolSizeBehavior(hardCap), the total number of active and idle connections cannot exceed the maximum pool size. Instead of creating a new connection for a connection request if an idle connection is unavailable, the Pool Manager queues the connection request until a connection is available or the request times out. This behavior is useful if your client or application server has memory limitations or if your database server is licensed for only a certain number of connections.
See “PooledConnectionDataSource” for more information about these methods.
Using Reauthentication with the Pool Manager
Reauthentication, or the ability to switch a user on a connection, is a useful strategy for minimizing the number of connections that are required in a connection pool. Refer to the DataDirect Connect Series for JDBC User’s Guide for an introduction to reauthentication.
If you are using the DataDirect Connection Pool Manager for connection pooling, you can enable reauthentication in the Pool Manager. By default, reauthentication is disabled. To enable reauthentication, call setReauthentication(enable) on the PooledConnectionDataSource. To disable reauthentication, call setReauthentication(disable).
The Pool Manager implements the maximum pool size, minimum pool size, and initial pool size attributes differently depending on whether reauthentication is enabled. For example, in both of the following figures, the maximum pool size is set to a value of 10, the minimum pool size is set to 5, and the initial pool size is set to 5.
Figure 9-3 shows a connection pool that is configured to work without reauthentication while using the default behavior for maximum pool size. When User A requests a connection, the Pool Manager assigns an available connection associated with User A. Similarly, if User B requests a connection, the Pool Manager assigns an available connection associated with User B. If a connection is unavailable for a particular user, the Pool Manager creates a new connection for that user. Because the maximum pool size is set to 10, a maximum of 10 idle connections can exist for each user. In this case, the total number of idle connections is 20, or 10 idle connections for each user.
Figure 9-3. Connection Pool Without Reauthentication
Connection pool without reauthentication showing separate groups of connections for different users within the same pool
 
The Pool Manager implements the minimum pool size and initial pool size in a similar way. The Pool Manager initially populates five connections for User A and five connections for User B, and ensures that, at a minimum, five idle connections are maintained in the pool for each user.
In contrast, Figure 9-4 shows a connection pool that is configured to work with reauthentication while using the default behavior for maximum pool size. The Pool Manager treats all connections as one group of connections. When User A requests a connection, the Pool Manager assigns an available connection associated with User A. Similarly, when User B requests a connection, the Pool Manager assigns an available connection associated with User B. If a connection is unavailable for a particular user, the Pool Manager assigns any available connection to that user, switching the user associated with the connection to the new user. In this case, the maximum number of idle connections in the pool is 10, regardless of how many users are using the connection pool.
Figure 9-4. Connection Pool With Reauthentication
Connection pool with reauthentication showing one group of connections for different users within the same pool
 
The Pool Manager initially populates the pool with five connections and ensures that, at a minimum, five idle connections are maintained in the pool for all users.