Using HAProxy to load balance your fusion cluster

Use Case: I have multiple fusion UI/API servers to distribute by query load. I want to be able to successfully round robin my requests between them

 

Solution: In this article we'll use HAProxy to load balance between the Fusion instances. 

Here is the config file that I used in this setup  . Let's call it haproxy.cfg

-------------------------------------------------------------------------------------------------------------------------

defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

frontend http-in
bind *:8080
default_backend fusion

backend fusion
balance roundrobin
option httpclose
option forwardfor
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
server fusion1 localhost:8764 maxconn 32 cookie 1
server fusion2 localhost:5678 maxconn 32 cookie 2
cookie WEBSVR insert

-------------------------------------------------------------------------------------------------------------------------

 

To test if the config file is valid we can run this command sudo haproxy -f haproxy.cfg -c

Now you can start HAProxy using this command - sudo haproxy -f haproxy.cfg

They key thing was making sure HAProxy played well with the Fusion's authentication. This was achieved by the way we're setting the cookie in the config file.

HAProxy docs are available here : http://cbonte.github.io/haproxy-dconv/configuration-1.5.html

To test it out I ran this command ( curl -u user:password http://localhost:8080/api/apollo/query-pipelines/default ) multiple times and could see the requests being alternating between the two fusion instances.

 

Caveats:

The settings work when the load balancer and fusion servers were on the same host. This would never be the case in a production system. The one additional change that you would need to make in that case is

On each of the fusion servers , under conf/config.sh edit the FUSION_CORS_ALLOW_ORIGIN to allow requests from the load balancer . For example the value of FUSION_CORS_ALLOW_ORIGIN=\* allows requests from any host.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk