Postgres connection pool

1,434 views
Skip to first unread message

mahe...@thoughtworks.com

unread,
Dec 15, 2015, 8:27:15 AM12/15/15
to golang-nuts
Hi All,

We are trying to do 10K simultaneous reads from postgres. For this, we are spawning 10K goroutines. The code is https://github.com/mahendrakariya/postgis_spike/blob/master/src/read_write.go

Whenever we run the program, it throws an error read: connection reset by peer. We have increased the postgres max_connections to 10000. We even added pgbouncer, but it looks like (based on logs) the connections are not going thru pgbouncer, rather they are directly hitting the database.

Could someone guide us how to do this? Also, is there a better approach other than spawning 10K goroutines?



Thanks.

James Bardin

unread,
Dec 15, 2015, 10:13:42 AM12/15/15
to golang-nuts


On Tuesday, December 15, 2015 at 8:27:15 AM UTC-5, mahe...@thoughtworks.com wrote:

Whenever we run the program, it throws an error read: connection reset by peer. We have increased the postgres max_connections to 10000. We even added pgbouncer, but it looks like (based on logs) the connections are not going thru pgbouncer, rather they are directly hitting the database.


"connection reset by peer"  means the remote host (the postgres server) reset the connection. There's nothing you can do in your Go code until the server is properly tuned to handle 10k connections. 

I don't know if postgres will accept that many simultaneous connections, but I can assure you if it does it's not going to handle it well. This is why you use a connection pool to limit the number of simultaneous connections to the appropriate number for your workload.  

Nigel Vickers

unread,
Dec 15, 2015, 10:29:17 AM12/15/15
to golang-nuts

Manlio Perillo

unread,
Dec 15, 2015, 2:24:38 PM12/15/15
to golang-nuts
Il giorno martedì 15 dicembre 2015 14:27:15 UTC+1, mahe...@thoughtworks.com ha scritto:
Hi All,

We are trying to do 10K simultaneous reads from postgres.

Why?
 
For this, we are spawning 10K goroutines. The code is https://github.com/mahendrakariya/postgis_spike/blob/master/src/read_write.go

Whenever we run the program, it throws an error read: connection reset by peer. We have increased the postgres max_connections to 10000. We even added pgbouncer, but it looks like (based on logs) the connections are not going thru pgbouncer, rather they are directly hitting the database.

Could someone guide us how to do this? Also, is there a better approach other than spawning 10K goroutines?

It depends on what you are trying to do.
Also note that pgbouncer it not stricly required, you can use Go concurrency support to limit the number of connections to the database.


Regards  Manlio
Reply all
Reply to author
Forward
0 new messages