TL;DR
PgBouncer's single-threaded nature limits throughput on multi-core systems, leading to inefficiencies. By deploying multiple PgBouncer processes with the SO_REUSEPORT option, ClickHouse Managed Postgres effectively utilizes all CPU cores.
✦ Why It Matters
Engineers should implement SO_REUSEPORT and peering in PgBouncer setups to maximize throughput and ensure effective query cancellation.
Key Takeaways
Full Summary
PgBouncer, a connection pooler for PostgreSQL, operates as a single-threaded process, which restricts its throughput on multi-core machines. In ClickHouse Managed Postgres, multiple PgBouncer instances are deployed, each bound to the same port using the SO_REUSEPORT socket option, enabling the kernel to distribute incoming connections across these processes.
This setup allows for better CPU utilization, as all cores can handle connections simultaneously. However, a challenge arises with query cancellation requests, which can be directed to the wrong PgBouncer process.
To address this, a peering mechanism was implemented, allowing processes to communicate and forward cancellation requests to the correct instance. As a result, ClickHouse Managed Postgres achieved a fourfold increase in throughput while maintaining effective query cancellation across the fleet.
Related