Connection pool timeout #1894
Replies: 1 comment 4 replies
-
Have you checked disk / CPU utilization? The only thing in go-pg that is worth checking is that you properly close transactions and statements (you say that you don't use them but still). Also
Make sure you are using PgBouncer / other connection pool. It is an easy but usually small win. With PgBouncer you can have as many connections in go-pg pool as you want, but it almost never matters. |
Beta Was this translation helpful? Give feedback.
-
We have 15 services in our system and we are planning to migrate the DB layer from non-relational database to relation database (PostgreSQL).
We started migration with a read and write heavy service(let's call it service1) which does thousands of reads and writes per minute.
On our dev env we are running PostgreSQL with other bunch of services on a machine with 8 cpus and 32GB memory.
Right now only service1 is using PostgreSQL.
We have kept the default pool size and that is 10, with 8 cpus maximum connection in the pool can be 80.
Service1 has to read and write thousands of data per minute and while doing that queries are timing out with this error:
pg: connection pool timeout
.Pool stat:
Connection pool stat for service1 : Hits: 1359475, Misses: 158, Timeouts: 114563, TotalConns: 80, IdleConns: 1, StaleConns: 78
From pool stat it is clear that service1 is running out of connections.
-We are not using transaction or statement.
-Our queries are not long running, they are very simple read, update, insert and delete.
-No join queries.
Sample code that we are using:
Questions:
Why service1 is running out of connections ? with the amount of load it is handling does it need more connections/resource or number of connections is sufficient and I am missing something?
By default PostgreSQL supports 100 connections, in my case all of my services will connect with the PostgreSQL container so 100 connections will not be sufficient given that just one service is using 80 and that too is not sufficient for it. So up to how many connections is it safe to keep in the connection pool ? (of course we need to keep it in mind that as the number of connections increases memory usage also increases)
Please help me with this, Thanks 🙏
Beta Was this translation helpful? Give feedback.
All reactions