Route traffic to node with lowest latency in HAproxy
Is it possible to route requests via HAproxy to a server that has the lowest latency from the source IP? This seems like a much needed requirement but I can't seem to find anything.
My problem is that our data center is on the West Coast of the United States and we are getting more and more demand from Europe, Asia, and South America, while the latency from these locations is making the application unusable.
Given that haproxy proxies requests, all traffic's going to go through haproxy anyway, so sending them to different places isn't going to help you any because all you'll be doing is adding more latency by running the traffic around more than it needs to be. You need to send the user directly to the closest available server, using a geographic or topological DNS engine.
HAproxy wouldn't be able to tell what the latency between the end-user and one of your servers would be, since the ping would need to be performed between those two parties.
What you may be able to do is to setup geodns, so that IPs allocated in Europe are sent to your European location, South America ones are sent to your Texas location and so on.
you can write your own simple inetd/xinetd script and make haproxy check health of backend server by that script. your own script can check backend machine load, number of connections and so on and decide to accept new traffic or not. hint: this script should behave like very simple http server, you can easily write it in shell. Only methods that you need to implement is 200 response and 500 to pass or deny further requests.