Connection Pooling limit question
Hello everyone,
I use connection pooling in my nextjs application. But there's something I'm having trouble understanding. In the documentation, it says that the connection limit in a pool is 64.
However, my nextjs application uses (among other db operations) a middleware for authentication that checks against the database.
Does this mean that beyond 64 users on my app, the database will slow down? Each time a user triggers the middleware, one connection out of 64 (lasting 5 minutes) is counted?
Could you please clarify this for me, as I think I'm mistaken.
Thank you and have a nice day
5 Replies
graceful-blue•2y ago
It's 64 connections per Postgres user. In other words, if you have one application that connects using
postgres://FOO:pass@ep-12345.aws-pooler.neon.tech and another application that connects using postgres://BAR:pass@ep-12345.aws-pooler.neon.tech each will have 64 connections available within the pooler to run concurrent operations (overall your application can open 10,000 connections to the pooler, the pooler itself forces them to share 64 internally)
Does this mean that beyond 64 users on my app, the database will slow down?Not necessarily. Each of your two applications can perform 64 concurrent queries. If 64 users make a request to your application at the same time, their queries can be run concurrently against the database. So long as queries use indexes, hit the cache, and your application is near your DB (same geo region), most queries will complete end-to-end in <10ms (https://neon.tech/demos/regional-latency) Load test your application to be sure, of course.
Neon Regional Latencies
View the latencies of queries to Neon databases across different deployment platforms and regions.
graceful-blue•2y ago
one connection out of 64 (lasting 5 minutes) is countedAs soon as the query completes, the connection is returned to be used by other queries. No 5 minute timeout
rare-sapphireOP•2y ago
All right, thank you very much for these explanations. The confusion came from the fact that I was thinking that a query (lasting a few milliseconds) equaled one connection out of 64, lasting for 5 minutes (confused by the Connections count monitoring in the Dashboard).
thanks for your help
graceful-blue•2y ago
You're welcome! So the connection count stays at 5 in the dashboard? I suspect this is becuase you're using the pooled URL. Internally the pool probably keeps the connection alive for 5 minutes. @Conrad Ludgate can confirm
rare-sapphireOP•2y ago
I was referring to this 5 minutes connection every time I query (but it appears they are not cumulative for each query so its fine). Thank you
