Database connections in depth

RSS

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


SHARE THIS.

Post new comment





500 characters left

Verification Image

SIGN UP.

Sign up to receive the latest news and updates from Server-Management via email.

News & Features Feed
Viewpoints Feed
FOLLOW US.
OUR SPONSOR.
Top 10 Most Popular Articles
Top 5 Jobs
DBA/Quality Assurance Manager - Industry Leader - Stoke
Posted:
2010-03-10
Location:
West Midlands, West Midlands
Salary range:
55000 - 60000
Salary period:
year
Description:

DBA/Quality Assurance Manager - Industry leader - Staffordshire Our well known client have an excellent opportunity for a Senior Data & Quality Manager to make a real impact in the business. The successful Data & Quality Assurance Manager will ideally have come up through the route of ... read more

IT Manager
Posted:
2010-03-10
Location:
Nottingham, Nottinghamshire
Salary range:
40000 - 45000
Salary period:
year
Description:

IT Manager Key Skill Set: .NET, C#, SQL, CSS, XHTML, XML, AJAX My client is recruiting for an IT Manager to head up an expanding .NET development team. The company are involved in the manufacturing and importing sector. The IT team is playing a vital role in the success and expansion of thi... read more

IT Security Manager- CISSP, CISM - Firewalls, IDS, NAS - £££
Posted:
2010-03-10
Location:
Kent, South East
Salary range:
45000 - 55000
Salary period:
year
Description:

Security, Access Control, Authentification, Data Security, Internet and email Security, Firewalls, IDS, NAS, RAS, Anti Virus, Pen Testing, ISO27001, CISSP, CISM Ignore all other IT Security related roles you have seen advertised in Kent and make this the first and only job you apply to in 2009 ... read more

IT Helpdesk Support Officer - MCDST - £25K - London Marylebone
Posted:
2010-03-10
Location:
West End, London
Salary range:
22000 - 25000
Salary period:
year
Description:

IT Helpdesk Support Analyst / IT Helpdesk Support Officer with an MCDST certification, experience of 1st and 2nd Line Support, ideally within an ITIL environment required by our Client, a medical organisation based on Harley Street, near London Marylebone for this immediate start. Salary to &pou... read more

IT Director - International Enterprise Systems (£90,000 to £100,000)
Posted:
2010-03-09
Location:
Middlesex, South East
Salary range:
90000 - 100000
Salary period:
year
Description:

IT Director. Based in West London. Salary of £90-£100K. Package of c£140K. Director of IT – International Enterprise Systems. IS Recruitment are looking to recruit an IT Director for their client based in the west of London. With a global presence, their products and thei... read more


Want to advertise here? Follow me!