Load balance active TCP sessions to AWS Aurora RDS

Viewed 335

I currently have a problem with properly load balance open TCP sessions (created by the RoR application) to dynamically created Aurora Postgresql read-replicas.

The issue with this is when TCP connections are already established to one read-replica, another read-replica is created. After that traffic from the first replica will not be distributed evenly to second one, since TCP connections are already established with first replica.

Attached chart represents current infrastructure setup. Please note that between read-replicas (servers) and application (client) there is a load balancer, provided by the Aurora service, which is based on DNS round-robin.

enter image description here

I've tried pgbouncer, pgpool and multiple Ruby gems (makara, fresh_connection), but none of them were able to load balance nor eliminate long lived TCP connections..

I went through many articles and they helped investigate and confirm the issue; however none of them present a solution.

So... as you can see I've tried obey this problem from application and network perspective, unfortunately without luck. Has anyone had the same problem?

2 Answers

Finally I've figured this out and the fix had to be applied on application level in order to stop keeping long live TCP connections.

Particulary in Ruby I had to set idle_timeout and reaping_frequency parameters. However here you can find parameters for other programming languages.

Hope it help someone in future. Cheers!

You could scale your load balancers along with the database instances.

                +----+     +--------+
             -> | LB | --> | Server |
+--------+ /    +----+     +--------+
| Client |     
+--------+ \    +----+     +--------+
             -> | LB | --> | Server |
                +----+     +--------+

As the client connects in a round robin fashion to the load balancers, the load balancers will do their jobs to limit to the total database connections per server. A simple routing policy in DNS with multiple load balancing hosts should suffice.

Related