remove

10.03.2023

A War Between MQTT Message Brokers : Mosquitto vs VerneMQ

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol for IoT (Internet of Things) and M2M (Machine-to-Machine) communication that is designed to be low overhead and easy to implement. It is based on the publish-subscribe model, where a client publishes a message to a topic on a broker, and any subscribers to that topic will receive the message.

MQTT brokers are servers that handle the distribution of messages to clients based on topic subscriptions. They provide a centralized location for publish and subscribe messages, allowing clients to communicate with each other without the need to exchange IP addresses or configure firewalls.

Mosquitto and VerneMQ are both open-source MQTT brokers that can be used to facilitate communication between MQTT clients. Below is a comparison of some features of the two brokers:

FeatureMosquittoVerneMQ
Protocol supportMQTT, MQTT-SNMQTT, MQTT-SN, WebSockets
AuthenticationYesYes
AuthorizationYesYes
BridgesYesYes
ClusteringYesYes
High availabilityYesYes
Message persistenceYesYes
Supported platformsWindows, Linux, macOS, Raspberry Pi, etc.Windows, Linux, macOS, FreeBSD, etc.
LicenseEclipse Public License 1.0Apache License 2.0

Here is an example of how you might deploy Mosquitto and VerneMQ on a Kubernetes environment:

Mosquitto

1. Create a Kubernetes Deployment resource that manages a set of replicas of your Mosquitto broker pods. For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mosquitto
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mosquitto
  template:
    metadata:
      labels:
        app: mosquitto
    spec:
      containers:
      - name: mosquitto
        image: eclipse-mosquitto:latest
        ports:
        - containerPort: 1883

2. Create a Kubernetes Service resource to expose your Mosquitto pods to other parts of the cluster. This can be either a ClusterIP Service, which exposes the service on a cluster-internal IP, or a LoadBalancer Service, which exposes the service externally using a cloud provider’s load balancer:

apiVersion: v1
kind: Service
metadata:
  name: mosquitto
spec:
  type: LoadBalancer
  selector:
    app: mosquitto
  ports:
  - protocol: TCP
    port: 1883
    targetPort: 1883

VerneMQ

1. Create a Kubernetes Deployment resource that manages a set of replicas of your VerneMQ broker pods. For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: vernemq
spec:
  replicas: 3
  selector:
    matchLabels:
      app: vernemq
  template:
    metadata:
      labels:
        app: vernemq
    spec:
      containers:
      - name: vernemq
        image: vernemq/vernemq:latest
        ports:
        - containerPort: 1883

2. Create a Kubernetes Service resource to expose your VerneMQ pods to other parts of the cluster. This can be either a ClusterIP Service, which exposes the service on a cluster-internal IP, or a LoadBalancer Service, which exposes the service externally using a cloud provider’s load balancer:

apiVersion: v1
kind: Service
metadata:
  name: vernemq
spec:
  type: LoadBalancer
  selector:
    app: vernemq
  ports:
  - protocol: TCP
    port: 1883
    targetPort: 1883

To stress test both brokers, you can use a load testing tool such as JMeter or Apache Bench to simulate a large number of concurrent MQTT clients publishing and subscribing to topics. You can then measure the performance of the brokers in terms of metrics such as the number of messages processed per second, the latency of the publish and subscribe operations, and the resource usage (e.g. CPU, memory, network) of the broker pods.

Here is a sample stress test using Apache JMeter to simulate a large number of concurrent MQTT clients publishing and subscribing to topics on an MQTT broker:

  1. Install JMeter on your local machine.
  2. Start JMeter and create a new “Test Plan” by right-clicking on the root node in the tree on the left side of the JMeter window and selecting “Add > Threads (Users) > Thread Group”.
  3. Add an MQTT Sampler to your Thread Group by right-clicking on the Thread Group and selecting “Add > Sampler > MQTT Sampler”.
  4. Configure the MQTT Sampler with the following settings:
  • Server Name or IP: the hostname or IP address of your MQTT broker
  • Port Number: the port number of your MQTT broker (e.g. 1883 for Mosquitto, 8080 for VerneMQ)
  • Client ID: a unique identifier for the MQTT client (e.g. “client1”)
  • Topic: the topic to publish or subscribe to (e.g. “test/topic”)
  • Quality of Service (QoS): the QoS level for the message (e.g. 0, 1, or 2)
  • Action: select “Publish” to publish a message to the topic or “Subscribe” to subscribe to the topic
  • Payload: the message payload to publish (if Action is “Publish”)
  1. Set the number of threads (users) and the ramp-up period in the Thread Group to the desired values. For example, to simulate 100 concurrent MQTT clients, set the number of threads to 100 and the ramp-up period to 100 (so that all threads are started at once).
  2. Add a listener to your Thread Group to view the results of the test. Right-click on the Thread Group and select “Add > Listener > View Results Tree”.
  3. Run the test by clicking on the “Start” button at the top of the JMeter window. The listener will show the results of the test, including the number of messages published or received, the response time, and any errors that occurred.