still getting too many clients already on the pooled 6543 string at 120 concurrent Connection Pooling
Serverless functions against a managed Postgres. Under a burst of about 120 concurrent invocations I get FATAL: sorry, too many clients already on maybe 15% of them.
I already moved the connection string to the pooled endpoint on port 6543. Same error. The diagram is how I understood the two paths - I thought moving to the bottom lane was the whole fix.
What I have checked: only one connection string in the environment, no long transactions, functions finish in about 90ms. What am I still doing wrong?
@two_vcpu_club · 2mo ago · 3 replies
The pooler is not the only pool in the picture. Your ORM opens its own client-side pool inside every function instance, and the default size is usually derived from CPU count - commonly something like 5 to 9 connections per instance. 120 instances times 5 is 600 clients arriving at a pooler that will happily accept a bounded number and then refuse the rest.
Append the limit to the pooled URL:
One connection per instance is correct for serverless. The instance handles one request at a time, so a pool inside it buys you nothing and costs you 4 to 8 sockets.
While you are there, confirm the host really is the pooled one. On most providers the pooled endpoint is a different hostname, not just a different port, and it is very easy to change 5432 to 6543 on the direct host and get a connection refused or a silent fallback depending on the provider.
Reply
Report
@adjunct_ora · 2mo ago
connection_limit=1took the error rate from 15% to zero in the same load test. I had read that parameter three times and assumed it was a maximum I would never reach.Reply
Report
@two_vcpu_club · 2mo ago
It reads like a safety limit and it is actually a per-instance allocation. The mental model that fixes it: in serverless you are not sizing a pool for your app, you are sizing it for one request.
Reply
Report