Your database isn't always the villain. Sometimes your app is just standing in line.
The math nobody does
20 pool connections × 100ms per query = ~200 ops/sec. Ask for 2,000 and the rest queue, then time out. Postgres looks bored because you never gave it work.
Measure the right thing
const t0 = performance.now();
const client = await pool.connect(); // waiting for a connection
const t1 = performance.now();
await client.query(sql); // actually running SQL
const t2 = performance.now();
client.release();
console.log({ poolWaitMs: t1 - t0, queryMs: t2 - t1 });
-
poolWaitMshigh,queryMslow → pool or app problem -
poolWaitMslow,queryMshigh → real database problem
Also check
- Event loop: one CPU-heavy sync loop freezes everything
-
File descriptors:
EMFILEshows up while the DB is healthy - Retries: 8K → 11K → 15K → 20K RPS. Use backoff + jitter + a cap
Where is the request waiting? Start there.
Top comments (0)