AMAZINGINDEX.COM 日报快照
52.3
VOL. 2026.07
2026.07.12
← 返回 2026.07.12 日报
日报快照 · Daily Snapshot
NO. 011

PgBouncer 多核扩展 4 倍吞吐

#ARTICLE HackerNews 2026.07.12
推荐指数 73.0 NO. 011 · 2026.07.12
发布2026/07/11Score119Comments15

ClickHouse 团队通过 so_reuseport 让多个 PgBouncer 进程绑定同一端口,突破单线程瓶颈。对高并发 Postgres 场景是零改造成本的即时方案。

PgBouncer 的单线程设计被诟病多年,但社区常见的 workaround 是用 HAProxy 或 Envoy 在前端做七层转发,架构复杂且增加一跳延迟。ClickHouse 的方案直接绕过了代理层,让内核做负载均衡,客户端完全无感知。

这个 trick 并非 PgBouncer 专属,任何单线程网络服务(如 Redis、Node.js 早期版本)都可以用同样模式扩展。如果你的服务还在用单进程监听端口,这是最低成本的多核化改造路径。

需要留意的是 so_reuseport 的调度策略是五元组哈希,长连接场景下可能出现热点核倾斜,短连接或配合连接重置策略效果更佳。

正面 15 条评论

核心争论:so_reuseport 多进程方案是否优于 HAProxy/替代代理,以及 PgBouncer 生态替代方案成熟度

odie5533

Article should show the config: [pgbouncer] listen_addr = 0.0.0.0 listen_port = 6432 so_reuseport = 1 peer_id = 1 unix_socket_dir = /tmp/pgbouncer1 [peers] 1 = host=/tmp/pgbouncer1 2 = host=/tmp/pgbouncer2 3 = host=/tmp/pgbouncer3 4 = host=/tmp/pgbou

nosefrog

Interesting. We run pgbouncer via kubernetes so it was straightforward to make multiple pgbouncer processes on one machine. Also straightforward to get them running on multiple machines, which helps because we run on Azure and they like to cause rolling outages across our fleet via VM maintenance...

saisrirampur

Ack, makes sense. I’m very curious on how this affects throughput due to a potential extra network hop from pgbouncer to Postgres. Expecting it to have a minor difference, but still curious.

替代方案: HAProxyOdysseypgdogrqbit
查看原文 →