We scaled PgBouncer to 4x throughput
5 hours ago
- #PgBouncer
- #Connection Pooling
- #Performance Optimization
- PgBouncer is single-threaded, using only one CPU core even on multi-core systems, which can bottleneck throughput.
- In ClickHouse Managed Postgres, multiple PgBouncer processes are run, scaled to available cores, using so_reuseport for kernel load balancing.
- Query cancellation is addressed via peering: processes forward cancel requests to the correct session owner, ensuring functionality across the fleet.
- Transaction mode pooling returns server connections after commits, with connection budgets split across processes to avoid oversubscribing Postgres.
- Performance tests show a fleet of 16 processes achieves ~336k TPS (4x higher) and utilizes ~8 cores, while a single process peaks at ~87k TPS and uses only one core.
- A single PgBouncer suffices at low concurrency, but under high load, multi-process fleets prevent the pooler from becoming a bottleneck.