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 want to use HAProxy as a load balancer. I want to put two rabbitmq server behind haproxy. Both the rabbitmq server are on different instance of EC2. I have configure HAProxy server by following this reference. I works but the problem is messages are not published in roundrobin pattern. Messages are publish only on one server. Is there any different configuration for my requirement?

My configureation in /etc/haproxy/haproxy.cfg

listen  rebbitmq *:5672
        mode    tcp
        balance roundrobin
        stats enable
        option  forwardfor
        option  tcpka
        server  web2 46.XX.XX.XXX:5672 check inter 5000 backup
        server web1 176.XX.XX.XX:5672 check inter 5000 backup
listen  web-service *:80
          mode    http
         balance roundrobin
        option httpchk HEAD / HTTP/1.0
         option httpclose
        option forwardfor
        option httpchk OPTIONS /health_check.html
        stats enable
        stats refresh 10s
        stats hide-version
        stats scope   .
        stats uri     /lb?stats
        stats realm   LB2\ Statistics
        stats auth    admin:Adm1nn

Update:

I have made some R&D on this and found that HAProxy is round robin the connection on the rabbitmq server. for ex: if i request for 10 connections then it will round robin the 10 connection over my 2 rabbitmq servers and publish the message.

But the problem is I want to round robin the messages, not connection. i.e if i send 1000 msg at a time from 1 connection then 500 msg should go to rabbit server1 and 500 msg should go to rabbit server2. What should be the configuration that i have to follow?

share|improve this question

2 Answers 2

As long as your client keeps open the connection to HAProxy, the connection from HAProxy to RabbitMQ connection won't move. HAProxy is a connection-based load balancer, not message based (as far as I know). It does not know when a message starts or ends (it would have to know the internal protocols for it to successfully do this).

In order to round robin the RabbitMQ servers, you'll need to have your client connect to HAProxy, send the message, then disconnect (don't keep the connection open). Reconnect to send the next message, then disconnect.

Each time you reconnect, HAProxy will/should move you to a different server.

share|improve this answer
    
I have tested with two tomcat instance behind HAProxy. And it works fine, by round robin the request to both the server. –  Anand Soni May 12 '12 at 4:37

Bad Rabbit. Bad. There is a degree of overhead when establishing a connection and a channel in RabbitMQ as well as the potential for increased latency when doing this in a clustered RabbitMQ environment. You definitely don't want to connect, send, disconnect. Leave the connection open. RabbitMQ is quite fast and there are ways to get really high performance out of it (e.g. use publisher confirms instead of transactions, use in-memory messages, etc.). You'll kill your application performance if you disconnection/reconnect on every. single. message.

How many messages per second does your application dispatch? 1000? RabbitMQ can handle it. 5000? Easy. 50K? Now we need to start doing a few things. Remember, this is through a single channel of the connection. If you're multi-threaded, you can get 50K per channel without much trouble.

share|improve this answer

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.