Connection Pool Calc

Optimal pool size from concurrency and database spec

Connection Pool Calc is a free online Developer tool. Optimal pool size from concurrency and database spec Related terms: 连接池 · pool · 连接数 · max connections · 数据库配置 · 并发. Use it on this page without signing in.

ms
x
公式 1(基于并发)
3
ceil(并发 × 耗时秒 × 系数)
公式 2(PG 官方)
9
核心数 × 2 + 1
推荐连接池大小
3
上限为 max_conn × 80% = 80
三组数值对比
公式 1(并发×耗时×系数)3
公式 2(核心数×2+1)9
推荐值(取三者最小)3
常用连接池配置参考(推荐值 3
HikariCP (Java)
# HikariCP (Java)
maximumPoolSize=3
minimumIdle=1
connectionTimeout=30000
idleTimeout=600000
maxLifetime=1800000
Node.js pg
# Node.js pg
const pool = new Pool({
  max: 3,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});
SQLAlchemy (Python)
# SQLAlchemy (Python)
engine = create_engine(
  DB_URL,
  pool_size=3,
  max_overflow=1,
  pool_timeout=30,
  pool_recycle=1800,
)
pgbouncer
# pgbouncer.ini
[databases]
mydb = host=127.0.0.1 dbname=prod

[pgbouncer]
pool_mode = transaction
default_pool_size = 3
max_client_conn = 100
reserve_pool_size = 1

公式 1 反映「同时正在执行的查询数」,公式 2(PostgreSQL 官方经验)反映「CPU 并行收益上限」,最终取较小值与数据库 80% 上限中的最小值,避免连接过多反而因上下文切换降低吞吐。

Help

使用说明

  1. 输入预估并发请求数
  2. 输入平均查询耗时(毫秒)
  3. 输入数据库最大连接数
  4. 自动计算推荐连接池大小和说明

计算公式

连接池大小 = 并发数 × 平均耗时(秒) × 安全系数(1.2)

参考 PostgreSQL 官方建议:

  • 公式:poolsize = (corecount × 2) + effectivespindlecount
  • 经验值:大多数应用 10-20 个连接即可达到最佳吞吐
  • 过多连接反而降低性能(上下文切换开销)

More Developer

View all

FAQ about Connection Pool Calc

What can Connection Pool Calc do?

Connection Pool Calc is a Developer tool. Optimal pool size from concurrency and database spec You can finish the job on this page.

Who should use Connection Pool Calc?

Anyone handling 连接池 · pool · 连接数 · max connections · 数据库配置 · 并发 who does not want to install desktop software can use Connection Pool Calc in the browser.

Is Connection Pool Calc safe? Is my data uploaded?

This tool runs in your browser. We do not collect the content you enter into Connection Pool Calc just because you used it.

What similar tools exist?

Related tools in the same Developer group are listed at the bottom of this page.