Databases Reference
In-Depth Information
Typically, creating a connection is one of the most performance-expensive oper-
ations that an application performs. Developers often assume that establishing a
connection is a simple request that results in the driver making a single network
round trip to the database server to validate a user's credentials. In reality, a con-
nection involves many network round trips between the driver and the database
server. For example, when a driver connects to Oracle or Sybase ASE, that con-
nection may require seven to ten network round trips. In addition, the database
establishes resources on behalf of the connection, which involves performance-
expensive disk I/O and memory allocation.
Your time will be well spent if you sit down and design how to handle con-
nections before implementing them in your application. Use the guidelines in
this section to manage your connections more efficiently.
Database applications use either of the following methods to manage connec-
tions:
•
Obtain a connection from a connection pool.
•
Create a new connection one at a time as needed.
When choosing a method to manage connections, remember the following
facts about connections and performance:
•
Creating a connection is performance expensive.
•
Open connections use a substantial amount of memory on both the data-
base server and the database client.
•
Opening numerous connections can contribute to an out-of-memory con-
dition, which causes paging of memory to disk and, thus, overall perfor-
mance degradation.
If your application has multiple users and your database server provides suffi-
cient database resources, using connection pooling can provide significant per-
formance gains. Reusing a connection reduces the number of network round
trips needed to establish a physical connection between the driver and the data-
base. The performance penalty is paid up front at the time the connection pool is
populated with connections. As the connections in the pool are actually used by