I was able to setup two pgbouncer
instances for database connection pooling, on a single VM (CentOS 7.0) listening to same port (6432) on two different TCP socket (I believe) using Linux Kernel feature SO_REUSEPORT
. From the documentations the kernel is supposed to load-balance between two socket and send the connection to one of socket at a time however in my case in the pgbouncer logs(separate files) I have seen both instances receives the same connection.
I have seen that the TCP connection distribution works based on some hashing which take ip/port combination for routing. Do I need to differentiate incoming connections somehow to achieve the expected behaviour of routing to single socket? For testing I am using a psql
client from another VM.
UPDATE
Even though both receives connection with login attempt to pgbouncer only one of them establishing connection with Database. Is this normal behaviour?
accept
will succeed in getting it, because there is only one connection. I don't see anything in the documentation which says otherwise. It's not that much different from sharing a single listener socket between multiple processes, only that there are multiple separate listener queues vs. one shared listener queue.