1

I wanted to use HAProxy for my web app for load balancing purpose. I am trying to add a new rabbitmq node dynamically in HAProxy server using command : haproxy -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid). I am doing tcp connection mode with leastconn balance algorithm in load balancing. What is expected is when there is 3 connection in one rabbitmq, I add a new rabbit server in HAProxy server. so the next connection would pass to 2nd rabbitmq server which is not happening in my case. It distributes the connection in haphazardly manner.

Here is my config file:

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout 5000
        srvtimeout 5000
listen rabbitmq 0.0.0.0:5672
         mode    tcp
         stats   enable
         balance leastconn
        option tcplog
        server  rabbit01 xx.xx.xx.xx:5672 check
        server  rabbit02 xx.xx.xx.xx:5672 check
listen tomcatq 0.0.0.0:80
         mode    http
         stats   enable
         balance roundrobin
         stats refresh 10s
        stats refresh 10s
        stats uri     /lb?stats
        stats auth    admin:admin
         option httplog         

What is the problem causing this behavior? Any suggestion will appreciated.

Anand Soni
  • 216
  • 2
  • 10

2 Answers2

0

The HAProxy docs say regarding the leastconn balancing algorithm:

Use of this algorithm is recommended where very long sessions are expected, such as LDAP, SQL, TSE, etc... but is not very well suited for protocols using short sessions such as HTTP.

I'm not sure how AMQP works but I don't think you'll see perfect results especially with a low number of connections with leastconn. Based off your details it doesn't seem like you're adding the node dynamically, it actually just appears you're restarting the HAProxy instance?

scott
  • 123
  • 2
  • 7
  • no i am not restarting HAProxy instance. I have checked that if I restart the HAProxy server my all connection which are already established will disconnected. So i am using the command described in this link: http://serverfault.com/questions/249316/how-can-i-remove-balanced-node-from-haproxy-via-command-line – Anand Soni May 14 '12 at 08:47
  • 1
    Yes you are. The command does a graceful handoff between the old process and the new one. The existing connections stay open on the old one and the new one services new requests. – JamesRyan Jan 26 '14 at 23:10
0

Not sure how do you add node to haproxy. Did the new node already exist in the haproxy.cfg? If you add node with the command: haproxy -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid), haproxy will be restarting, all the connection info will be cleared. So the new connection may not be dispatched to 2nd rabbitmq server.

Avalon
  • 101