Databases 9 min read

How to Size Database Connection Pools: Lessons from HikariCP Performance Tests

This article explains why a small database connection pool often yields better performance, presents real‑world Oracle and PostgreSQL benchmark results, discusses CPU, disk and network bottlenecks, and provides a practical formula for calculating the optimal pool size based on core count and effective disks.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
How to Size Database Connection Pools: Lessons from HikariCP Performance Tests

The author shares a translation of a HikariCP wiki article that dispels common misconceptions about database connection pool sizing.

Performance tests on an Oracle system with 9600 concurrent threads showed that a pool of 2048 connections caused long queue waits (33 ms) and high CPU usage, while reducing the pool to 1024 cut wait events in half without hurting throughput. Further shrinking the pool to 96 connections reduced average wait to 1 ms and SQL execution time to 2 ms, dropping response latency from ~100 ms to 3 ms.

The article explains that the root cause is thread‑context‑switch overhead and I/O blocking. On a CPU‑bound system, having more threads than cores leads to slower execution; however, when threads spend time blocked on disk or network I/O, a higher thread count can improve utilization.

Three primary bottlenecks are identified: CPU, disk, and network. Disk seeks and rotational latency dominate on HDDs, while SSDs reduce blocking, allowing fewer threads. Network bandwidth also contributes to I/O wait, but is usually a secondary concern.

Based on these observations, the author proposes a simple heuristic for calculating the optimal connection pool size: 连接数 = ((核心数 * 2) + 有效磁盘数) For a 4‑core i7 server with one effective disk, the formula yields 9 connections (rounded to 10). Testing shows that exceeding this number quickly degrades response time and throughput.

Additional recommendations include using separate pools for long‑running and short‑running transactions, matching the pool size to the number of concurrent queries the database can handle, and avoiding overly large pools that waste resources.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

optimizationScalabilityConnection PoolHikariCP
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.