Works on this device
Connection Pool Calculator
Work out how many connections a database pool needs. Use Little's law with your query rate and the time each query holds a connection, the starting rule of cores × 2 + effective spindles, or the connection limit of the database shared by all instances. You type every figure.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Calculate.
Your result
How it was worked out
How to use this calculator
- Choose a way to work it out. Pool size from a query rate and a hold time is the first choice.
- Type the queries at your busiest time and the time each one holds a connection. Or type the cores of the database server, or its connection limit and your instances.
- Choose Calculate. Whole connections are rounded up for a need and down for a share of a limit.
The three ways
- Little's law: connections in use on average = queries each second × time each query holds a connection. Add room to spare for bursts. The most a pool can serve = connections ÷ hold time.
- Cores and disks: connections = cores × 2 + effective spindle count. This is a starting point for all active connections to one database server, from the PostgreSQL wiki and the HikariCP wiki "About Pool Sizing". Test it under load.
- The limit of the database: largest pool for each instance = (connection limit − connections kept for administrators − other programs) ÷ instances running at the same time.
Worked examples
Little's law: 1,200 queries each second that each hold a connection for 25 ms keep 1,200 × 0.025 = 30 connections in use. With 20% to spare the pool needs 36 connections.
A pool you have: 30 connections and 25 ms per query serve at most 30 ÷ 0.025 = 1,200 queries each second, so at 1,200 the pool is full all the time.
Cores and disks: a database server with 8 cores and all data in memory: 8 × 2 + 0 = 16 active connections. With 4 instances, each pool gets 4.
The limit: a limit of 100, 3 kept for administrators and 10 for other programs leave 87. With 4 instances and 1 extra during a deploy, each pool may have at most 87 ÷ 5 = 17 connections. A planned pool of 20 needs 20 × 5 + 3 + 10 = 113, which is 13 over the limit.
Other tools for the same subject
- For queries each second from concurrency and latency, use the Query Throughput Calculator.
- To see which connection limit fills first and when, use the Connection Saturation Calculator.
- For connections open at the same time from users or a list of sessions, use the Concurrent Connection Calculator.
- To size a pool of worker threads, use the Thread Pool Size Calculator.
Limits you should know
- Little's law gives an average over a steady time. Bursts need more, so type the rate of your busiest hour and keep room to spare.
- More connections than the cores and disks can serve do not make a database faster: the extra queries wait inside it.
- The example values are for trying the tool. Read your own limits, settings and counts. The tool connects to no database.