Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load blancing MQTT broker

Is it possible to load balance MQTT broker? Can I use ELB to load balance MQTT? Any pointers in this direction would be helpful. I hit upon http://www.slideshare.net/kellogh/mqtt-kafka-33100776 but it did not help much.

like image 449
chochim Avatar asked Jul 11 '15 18:07

chochim


People also ask

Is MQTT scalable?

MQTT brokers can be scaled vertically or horizontally. For example, the Mosquitto broker provides horizontal scalability options. Horizontal scalability is hard to achieve as it requires manual configuration and in-depth knowledge of networks.

How many connections can a MQTT broker handle?

These brokers are again interconnected using DMR. This enables us to assure that our platform has a capability to handle greater than 1 million concurrent connections.


4 Answers

Load balancing MQTT brokers is not supported out-of-the-box by most MQTT brokers. There are brokers available which support clustering, though. Take a look at this list to find out a broker which suits your clustering requirements.

This blog post is a bit dated but might still be useful if you want to learn about MQTT broker clustering: http://www.hivemq.com/building-a-high-availability-mqtt-cluster/

To answer your question: The MQTT broker HiveMQ works perfectly with AWS ELB for load balancing across several availability zones. You might want to increase the default ELB timeout for TCP connections to your MQTT keep-alive time you are using for your application. You can even use Auto Scaling groups for scaling elastically if needed. HiveMQ can use S3 for the discovery of other cluster nodes so you can add and remove cluster nodes at runtime.

I don't know if other brokers work as seamlessly with the AWS ELB. If HiveMQ does not suit your needs, best would be to search for a broker in the list linked above and try it :)

Disclaimer: I'm working for the company which develops HiveMQ.

like image 95
Dominik Obermaier Avatar answered Oct 23 '22 10:10

Dominik Obermaier


Use HAProxy. A free, fast and reliable solution offering high availability, load balancing and proxying for TCP and HTTP based applications. It’s suited for very high traffic web sites.

like image 40
Arbaz Alam Avatar answered Oct 23 '22 08:10

Arbaz Alam


You can't load balance MQTT Brokers like you would load balance web servers! The LB solution has to persist the connection on the MQTT Topic field, NOT the client's IP:Port...otherwise not all subscribers will get published messages. A 'Publisher' message only gets sent to a single MQTT Broker, so only that Broker will resend the messages. If a 'Subscriber' for the same MQTT Topic goes to a different Broker, it won't be receiving the messages from the Publisher connected to the other Broker. You can, of course, bridge your MQTT Brokers so that all of them get the message, but then what's the point of LB-ing them?? You're not really scaling them at that point, which is probably why you want to LB them in the first place. An F5 BIG-IP can be used to do true MQTT LB, IF you create the iRule script to do the LB decision on the MQTT Topic. There are companies out there doing this today.

like image 43
JD Allen Avatar answered Oct 23 '22 08:10

JD Allen


(Adding to @JD Allens response) Load balancing MQTT or TCP in general will mostly not work as intended if you keep state on servers like MQTT(subscriptions). For example if you have two MQTT backend servers behind the LB, half of your MQTT clients will connect to one MQTT broker and the other half to the other. Since these two brokers are not interconnected by any means, client will have no info about of what is going on in the other broker (subscriptions and publishes). You have two options:

  • Just configure the load balancer that will direct all connections to a single broker and only fail over to the other in case of error. Only one broker should be up at a given time (this is not load balancing per se).

  • Use a clustered MQTT broker like HiveMQ, EMQX etc. They will interconnect the backend brokers.

like image 43
ᐅdevrimbaris Avatar answered Oct 23 '22 10:10

ᐅdevrimbaris