We scaled PgBouncer to 4x throughput(clickhouse.com)
213 points by saisrirampur 21 hours ago | 52 comments
tl;dr: ClickHouse scaled PgBouncer 4x (from ~87k to ~336k TPS on a 16-vCPU box) by running a fleet of PgBouncer processes sharing one port via SO_REUSEPORT, since PgBouncer is single-threaded and otherwise pins to one core. To make this work correctly, they use peering to forward Postgres cancel requests to the process owning the session, and divide connection limits (max_client_conn, max_db_connections) across the fleet to avoid oversubscribing Postgres.
HN Discussion:
  • Alternative tools like Odyssey or pgdog already solve this scaling problem
  • ~Running multiple PgBouncer instances via Kubernetes/HAProxy is a simpler existing solution
  • Curious questions about how peering and SO_REUSEPORT work in practice
  • Questioning why PgBouncer needs custom cancellation handling at all
  • General appreciation for PgBouncer and frustration with Postgres's connection model