Pranit PatilMumbai IST
All notes

Performance · Updated 28 Nov 2026

Why a connection pool was the biggest win on a 1 GB server

Where a request's time actually went, and why a bigger pool made things slower.

The 1 GB Server Test measures how much traffic a 1 vCPU, 1 GB DigitalOcean droplet can serve with Postgres on the same box, changing one thing per run. The very first change, adding a connection pool, was the biggest win of the whole project, so it is worth understanding why.

Where the time went without a pool

The baseline Express app opened a fresh Postgres connection for every request and closed it afterwards. Each response carried a Server-Timing header, which split the server's time into parts.

  • Connect and authenticate181 ms
  • Database queries38 ms
  • App code0.5 ms
Fig 1 Median times from the Server-Timing header in the no-pool baseline. The whole request took about 227 ms on the server, and 181 ms of it was connecting and authenticating.

Opening a Postgres connection is real work. There is a TCP handshake, Postgres starts a new backend process for the session, and SCRAM authentication runs a deliberately slow password hash. On a machine with one CPU, all of that competes with the queries themselves. The baseline was CPU-bound, at 98%.

What a pool changes

No pool

  1. Request

  2. Connect + auth

    every time

  3. Query

  4. Close

Pool of 10

  1. Request

  2. Borrow a connection

    or wait for one

  3. Query

  4. Return it

    stays open

Fig 2 Without a pool every request pays for a new connection. With one, a small set of connections stays open and requests take turns using them.

Switching to pg.Pool with its defaults (at most 10 connections) took capacity from 100 to 1,350 concurrent users, and throughput from 46.7 to 619 requests per second.

Why 20 connections lost to 10

  • Express, no pool100 users
  • Express, pool of 101,350 users
  • Express, pool of 201,200 users
  • FastAPI, no pool60 users
  • FastAPI, pool of 10600 users
Fig 3 Highest number of concurrent users that still met the latency rules (p95 under 800 ms, p99 under 1 s, errors under 1%).

It is tempting to think more connections means more work done at once. But one vCPU can only do one query's work at a time. Doubling the pool doubled how many queries were fighting for that CPU, and query time at p95 roughly doubled too, from 37–48 ms to 83–102 ms.

With 10 connections, the overload looked different. Past the limit, the queries themselves stayed fast (p95 at most 48 ms) and the extra latency was requests waiting for a free connection. That is the pool doing its job: it is a queue in front of the database, and a short queue is better than an overloaded CPU.

What I took from it

Where it went from here

The pool was step one. A 1-second feed cache, plain node:http and then Bun took the same box to 4,500 users. The full path is in the project write-up.

Next noteHow an LSM tree keeps writes fastWrite path, SSTables, reads and compaction, from building a Redis-compatible store in Go