Database connections in depth
Story by John Goodson and Rob Steward, 09-07-2009, 0 comment
The way you implement database connections may be the most important design decision you make for your application.
In this extract from The Data Access Handbook, John Goodson and Rob Steward explain the details of how to make that choice.
When you're designing a database application, the connection type might be something you think is relatively unimportant, but you'd be wrong. Connections are important for a number of reasons:
- Creating a connection is performance-expensive compared to all other tasks a database application can perform.
- Open connections use a substantial amount of memory on both the database server and database client machines.
- Establishing a connection takes multiple network round trips to and from the database server.
- Opening numerous connections can contribute to out-of-memory conditions, which might cause paging of memory to disk and, thus, overall performance degradation.
- In today’s architectures, many applications are deployed in connection pooled environments, which are intended to improve performance. However, many times poorly tuned connection pooling can result in performance degradation. Connection pools can be difficult to design, tune, and monitor.
Your choices for implementing connections are as follows:
- Obtain a connection from a connection pool.
- Create a new connection one at a time as needed.
The right choice mainly depends on the CPU and memory conditions on the database server.
Why Connections Are Performance-Expensive
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 initialize a user. In reality, a connection typically involves many network round trips between the driver and the database server. For example, when a driver connects to Oracle or Sybase, that connection may take anywhere from seven to ten network round trips to perform the following actions:
• Validate the user’s credentials.
• Negotiate code page settings between what the database driver expects and what the database has available, if necessary. • Get database version information.
• Establish the optimal database protocol packet size to be used for communication.
• Set session settings.
In addition, the database management system establishes resources on behalf of the connection, which involves performance-expensive disk I/O and memory allocation. You might be thinking that you can eliminate network round trips if you place your applications on the same machine as the database system. This is, in most cases, not realistic because of the complexity of real-world enterprises—many, many applications accessing many database systems with applications running on several application servers. In addition, the server on which the database system runs must be well tuned for the database system, not for many different applications. Even if one machine would fit the bill, would you really want a single point of failure?
Using Connection Pooling
A connection pool is a cache of physical database connections that one or more applications can reuse. Connection pooling can provide significant performance gains because reusing a connection reduces the overhead associated with establishing a physical connection. The caveat here is that your database server must have enough memory to manage all the connections in the pool.
One important point - we are talking about client-side connection pooling (connection pooling provided by database drivers and application servers), not database-side connection pooling (connection pooling provided by database management systems). Some database management systems provide connection pooling, and those implementations work in conjunction with client-side connection pooling. Although specific characteristics of database-side connection pooling vary, the overall goal is to eliminate the overhead on the database server of establishing and removing connections. Unlike client-side connection pooling, database-side connection pooling does not optimize network round trips to the application.
As we stated previously, connecting to a database is performance-expensive because of the resource allocation in the database driver (network round trips between the driver and the database), and the resource allocation on the database server. Client-side connection pooling helps solve the issue of expensive resource allocation for both the database driver and database server. Database-side connection pooling only helps solve the issue on the database server.
Next page: How Connection Pooling Works
Sign up to receive the latest news and updates from Server-Management via email.
Iometer disk I/O monitor
Network Monitor Tutorial
ZyXEL P660HN-F1Z
DrayTek Vigor 2820 router
LaCie 5big Network NAS
Lab: multifunction printers
Lenovo W700
Database connections in depth
Watchguard Firebox X Peak X8500
- Posted:
- 2010-02-08
- Location:
- Watford, Hertfordshire
- Salary range:
- 40000 - 50000
- Salary period:
- year
Description:
Development Manager C#.Net – Watford £50k Development Manager with knowledge of C# web development is required by an expanding company based near Watford. Candidates can expect a salary of up to £50,000. The purpose of the role is to create project delivery timeframes an... read more
- Posted:
- 2010-02-08
- Location:
- Essex, South East
- Salary range:
- 30000 - 40000
- Salary period:
- year
Description:
Senior Software Developer C#, OO, ASP.Net, VB.Net, Postgres, Ajax, CSS, Java, IIS, Linux. Senior Software Developer - A rapidly growing worldwide communications provider, seeking an experienced Senior Software Developer to bring development in house. Our client is a a market leading pr... read more
- Posted:
- 2010-02-08
- Location:
- Essex, South East
- Salary range:
- 30000 - 40000
- Salary period:
- year
Description:
Senior Software Developer C#, OO, ASP.Net, VB.Net, Postgres, Ajax, CSS, Java, IIS, Linux. Senior Software Developer - A rapidly growing worldwide communications provider, seeking an experienced Senior Software Developer to bring development in house. Our client is a a market leading pr... read more
- Posted:
- 2010-02-08
- Location:
- Essex, South East
- Salary range:
- 30000 - 40000
- Salary period:
- year
Description:
Senior Software Developer C#, OO, ASP.Net, VB.Net, Postgres, Ajax, CSS, Java, IIS, Linux. Senior Software Developer - A rapidly growing worldwide communications provider, seeking an experienced Senior Software Developer to bring development in house. Our client is a a market leading pr... read more
- Posted:
- 2010-02-08
- Location:
- Essex, South East
- Salary range:
- 30000 - 40000
- Salary period:
- year
Description:
Senior Software Developer C#, OO, ASP.Net, VB.Net, Postgres, Ajax, CSS, Java, IIS, Linux. High availability transactional web sites. Senior Software Developer - A rapidly growing worldwide communications provider, seeking an experienced Senior Software Developer to bring developm... read more
Want to advertise here? Follow me!