65 lines
6.0 KiB
HTML
65 lines
6.0 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
|
||
|
|
||
|
<title>Connection pooling</title>
|
||
|
</head>
|
||
|
|
||
|
<BODY>
|
||
|
<!-- Java sync-link -->
|
||
|
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
||
|
|
||
|
<h5><a name="datapool"></a>Connection pooling</h5>
|
||
|
|
||
|
<p>When accessing any database, the initial database connection is an expensive operation. Connection pooling enables administrators to establish a pool of database connections that applications can share on an application server. When connection pooling capabilities are used, performance improvements up to 20 times the normal results are realized.</p>
|
||
|
|
||
|
<p>Each time a resource attempts to access a back-end store (such as a database), the resource must connect to that data store. A connection requires resources to create, maintain, and then release the connection when it is no longer required.</p>
|
||
|
|
||
|
<p>The total data store overhead for an application is particularly high for Web-based applications because Web users connect and disconnect more frequently. In addition, user interactions are typically shorter. Often, more effort is spent connecting and disconnecting than is spent during the interactions. Also, because Internet requests can arrive from virtually anywhere, you can find usage volumes large and difficult to predict.</p>
|
||
|
|
||
|
<p>To help lessen these overhead problems, WebSphere Application Server - Express enables administrators to establish a pool of back end connections that applications can share on an application server. Connection pooling spreads the connection overhead across several user requests, thereby conserving resources for future requests.</p>
|
||
|
|
||
|
<p>WebSphere Application Server - Express supports JDBC 2.0 Standard Extension APIs to provide support for connection pooling and connection reuse. The connection pool is used to direct JDBC calls within the application.</p>
|
||
|
|
||
|
<p>If clones are used, one data pool exists for each clone. This is important when configuring the database maximum connections.</p>
|
||
|
|
||
|
<p><strong>Benefits of connection pooling</strong></p>
|
||
|
<p>Connection pooling can improve the response time of any application that requires connections, especially Web-based applications. When a user makes a request over the Web to a resource, the resource accesses a data source. With connection pooling, most user requests do not incur the overhead of creating a new connection because the data source can locate and use an existing connection from the pool of connections. When the request is satisfied and the response is returned to the user, the resource returns the connection to the connection pool for reuse. The overhead of a disconnect is avoided. Each user request incurs a fraction of the cost for connecting or disconnecting. After the initial resources are used to produce the connections in the pool, additional overhead is insignificant because the existing connections are reused.</p>
|
||
|
|
||
|
<p><strong>When to use connection pooling</strong></p>
|
||
|
<p>Use WebSphere connection pooling in an application that meets any of the following criteria:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>It cannot tolerate the overhead of obtaining and releasing connections whenever a connection is used.</li>
|
||
|
<li>It requires Java Transaction API (JTA) transactions within WebSphere Application Server - Express.</li>
|
||
|
<li>It needs to share connections among multiple users within the same transaction.</li>
|
||
|
<li>It needs to take advantage of product features for managing local transactions within the application server.</li>
|
||
|
<li>It does not manage the pooling of its own connections.</li>
|
||
|
<li>It does not manage the specifics of creating a connection, such as the database name, user name, or password.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p><strong>How connections are pooled together</strong></p>
|
||
|
<p>Whenever you configure a unique data source or connection factory you are required to give it a unique Java Naming and Directory Interface (JNDI) name. Use this name, along with its configuration information, to create a connection pool. A separate connection pool exists for each configured data source or connection factory.</p>
|
||
|
|
||
|
<p>It is also important to note that when using connection sharing, it is only possible to share connections obtained from the same connection pool.</p>
|
||
|
|
||
|
<p><strong>Avoiding a deadlock </strong></p>
|
||
|
<p>Deadlock can occur if the application requires more than one concurrent connection per thread, and the database connection pool is not large enough for the number of threads. For example, each application thread requires two concurrent database connections, and the number of threads is equal to the maximum connection pool size. Deadlock can occur when both of the following are true:</p>
|
||
|
<p>
|
||
|
<ul>
|
||
|
<li>Each thread has its first database connection, and all connections are in use.</li>
|
||
|
<li>Each thread is waiting for a second database connection, and none become available, because all threads are blocked.</li>
|
||
|
</ul>
|
||
|
</p>
|
||
|
<p>To prevent deadlock in this example, the value set for the database connection pool must be at least one higher, allowing one of the waiting threads to complete its second database connection and free up to allow other database connections.</p>
|
||
|
|
||
|
<p>To avoid deadlock, code the application to use, at most, one connection per thread. If the application is coded to require C concurrent database connections per thread, the connection pool must support at least the following number of connections, where T is the maximum number of threads.</p>
|
||
|
<pre>T * (C - 1) + 1</pre>
|
||
|
<p>The connection pool settings are directly related to the number of connections that the database server is configured to support. If the maximum number of connections in the pool is raised, and the corresponding settings in the database are not raised, the application fails and SQL exception errors are displayed in the stderr.log file.</p>
|
||
|
|
||
|
</body>
|
||
|
</html>
|
||
|
|