TLDR Connection initiation overhead is killing your webapp — by Eric Worden

What is the proper max_connections for PostgreSQL? — is the wrong question! Use a connection pool, like PgBouncer.

pavel trukhanov
some-tech-tldrs

--

Will more connections will get me more throughput?is also wrong.

The right one is

How can my existing set of connections be used efficiently?

Connections carry overhead:

  • overhead of initializing each connection
  • overhead of maintaining an open connection
  • overhead of process concurrency in the OS
  • overhead of concurrency in the database

connect-query-disconnect cycle is so slow!

Simple pgbench benchmark with and without pgbouncer (a connection pooler) illustrate connection initiation overhead:

The benchmarks with connection pooling produced eight times more transactions while using less CPU time!

Try okmeter.io — a monitoring solution that will show you everything about Postgresql and PgBouncer operations.

--

--