Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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?

share|improve this answer
    
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: serverfault.com/questions/249316/… –  Anand Soni May 14 '12 at 8:47
    
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 at 23:10
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.