ClickHouse published a blog post describing how they scaled PgBouncer, a popular PostgreSQL connection pooler, to 4x its original throughput by enabling SO_REUSEPORT and implementing peering between processes. PgBouncer is widely used in PostgreSQL deployments, and this performance improvement benefits many users who rely on it for connection pooling. The techniques used can inspire similar optimizations in other network services. SO_REUSEPORT allows multiple processes to bind to the same TCP port, distributing incoming connections evenly. Peering forwards cancellation requests to the correct process, eliminating bottlenecks and improving scalability.
Background
PgBouncer is a lightweight connection pooler for PostgreSQL that manages database connections to improve performance. Traditionally, it runs as a single process, limiting throughput on multi-core systems. SO_REUSEPORT is a Linux socket option that enables multiple processes to accept connections on the same port. Peering in PgBouncer allows separate processes to coordinate and forward cancellation requests, which historically caused issues when a cancellation landed on the wrong process.
References
Discussion
Community members suggested alternatives like Odyssey and pgdog, and asked about the simplicity of setting up peering. Others shared experiences running multiple PgBouncer processes on Kubernetes or in multi-machine setups.