DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Connection Pooling
  • A Maven Story
  • Java EE 6 Pet Catalog with GlassFish and MySQL
  • API Performance Tuning

Trending

  • The Missing `bandit` for AI Agents: How I Built a Static Analyzer for Prompt Injection
  • Implementing Observability in Distributed Systems Using OpenTelemetry
  • Every Cache Miss Is a Tiny Tax on Your Performance
  • Implementing Secure API Gateways for Microservices Architecture
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Optimum Database Connection Pool Size

Optimum Database Connection Pool Size

Want to figure out the best size for your connection pool? Here's how the math pans out, courtesy of some simple logic.

By 
Anubhav R Mulchandani user avatar
Anubhav R Mulchandani
·
Nov. 28, 16 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
41.6K Views

Join the DZone community and get the full member experience.

Join For Free

Long ago, I was working on a project where I dealt with a situation — what should be the optimum size of connection pool?

While I was aware that it had to be configured on the application server side (web sphere application server v.5.x, in this case), I did not know the optimum pool size.

So I started having a discussion with my peers to try to understand more about it. I received some input and one of them was good enough, backed by strong reasoning, for me to recommend it to the admin. So what was it?

It’s quite simple and straightforward — look for the maximum size of the web container thread pool.

What Is a Web Container Thread Pool?

This pool consists of a number of threads that an application server will create and use to process the requests concurrently. So, for example, if the thread pool size is 50 (not realistic figure), the maximum number of requests an application may process concurrently will be 50.

So, the connection pool size has to be lower than the maximum size of the web container thread pool. Does it look reasonable and logical?

Let’s Analyze It

Max size of web container thread pool: 50

Max size of connection pool size: 65

Now if there are 50 concurrent requests coming to our application server, only 50 connections will be consumed by those 50 requests. But we are still left with 15 more connections — a sheer waste of resource. So, keeping performance statistics in mind; the connection pool size should be lower than the maximum thread pool size.

It may be 30/35 in our case.

There is another factor/attribute that should be considered, connection timeout. This should be calculated by obtaining the average time a database operation takes in our application, plus a few seconds more (let’s say 5).

I believe this post will be quite enlightening for many, and I  hope to receive your input so that I may update my post accordingly.

I always believe that knowledge is free and should always be free.

Connection pool Database connection Web container application Application server

Opinions expressed by DZone contributors are their own.

Related

  • Connection Pooling
  • A Maven Story
  • Java EE 6 Pet Catalog with GlassFish and MySQL
  • API Performance Tuning

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook