Toolvito

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

Little's law: connections in use on average = queries each second × time each query holds a connection. It also gives the most a pool can serve and how busy it is.

Your values

At your busiest time. Count what holds a connection: one query, or a whole transaction.

From taking a connection from the pool until giving it back: the query time plus any work the program does while it holds the connection.

Extra connections for bursts above the average. Your own choice: type 0 for none.

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.

How to use this calculator

  1. Choose a way to work it out. Pool size from a query rate and a hold time is the first choice.
  2. 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.
  3. 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

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.

Related tools