Recommendations in regards to setting Prisma's poo...
# orm-help
c
Recommendations in regards to setting Prisma's pool size? We're on Render and our Postgres plan includes 97 connections. Just learned the hard way that setting the pool size close to 97 is NOT a good idea because devs also need some of those connections for using SQL clients. Just wondering if we should set the pool size as high as possible while leaving plenty of connections free for devs i.e. 70 out of 97 available, or is there some downside to that maybe in terms of RAM usage by either Postgres or Prisma Client? We're running Apollo Server on Node.
âś… 1
n
Hi Chris đź‘‹ I would recommend you to integrate metrics (In Preview) This would allow you to get information about
pool_active_connections
,
pool_idle_connections
,
pool_wait_count
Monitoring this information should give you an idea of what ideal threshold value for pool size could you configure.
d
A few tips on connection management. Don’t promise.all() across input - that requires one connection per element. Also await all your data pulls to make them share connections
c
@Dave Edelhart thanks for the pointer, I didn't realize how things are coded would affect connections. I've been using Promise.all() for inputs, but with
p-limit
throttling async requests to less than our number of database connections. Seems to work O.K. I've also used
.reduce()
to run async requests serially which seems to work too.
d
When you run parallel queries they are handled when the pool has an empty connection - but if you have a thousand or so things to iterate over, for instance, you can create a traffic jam pretty easily; best not to create circumstances where that can happen - especially because you have potential parallel REQUESTS which all make demands on the pool. SO parallel requests * parallel demands on a pool creates an O(2) problem for the pools.
One example of how that can play out is I had a table I was logging error messages to; for some reason those messages always seemed to be the things that took my pool down. I realized if I await’ed the messages, they caused less damage.