Course contentsShow
← System Design
Lesson 269 of 1,9198. Database Performance OptimizationFree lesson

Pool Size Configuration

Determining optimal pool size using the formula: connections = ((core_count * 2) + effective_spindle_count).

Pool Size Configuration

What you'll learn: How to calculate the ideal number of database connections to keep in your connection pool without wasting resources or starving requests.


Why Pool Size Matters

Connection pooling only works well if you configure the right pool size. Too few connections and your application threads wait in line, hurting performance. Too many connections and you waste memory, overwhelm the database, and ironically slow everything down.

The Formula

There's a practical formula used in production systems:

connections = ((core_count * 2) + effective_spindle_count)

Let's break this down:

  • core_count: The number of CPU cores your database server has
  • effective_spindle_count: The number of physical hard drives (spindles) handling your data; for SSDs or cloud storage, use 1

Why This Works

Think of your database like a restaurant kitchen. You need enough chefs (connections) to handle orders, but not so many they bump into each other. The formula balances:

  • CPU cores × 2: While one query waits for disk I/O, another can use the CPU
  • + spindle count: Traditional spinning disks benefit from parallel operations; SSDs less so

Example

If your database runs on a server with 4 CPU cores and uses an SSD:

connections = ((4 * 2) + 1) = 9 connections

Start with 9 connections in your pool.

Tuning in Practice

This formula is a starting point, not gospel. Monitor your application under real load and adjust. If queries queue up during peak hours, increase slightly. If the database CPU stays low but memory is high, decrease.

Key Takeaway: Use connections = ((core_count * 2) + effective_spindle_count) as your baseline pool size, then tune based on actual performance metrics.