remove

10.01.2023

How To Stress Test Mosquitto MQTT client

Here is a basic example of a Python script that can be used to perform a stress test on a Mosquitto MQTT client :

This script creates an MQTT client, connects it to the specified broker, and then sends 100,000 messages to the specified topic. The delay between each message is set to 0.001 seconds to simulate a high rate of messages being sent. You can modify this script to increase or decrease the number of messages, change the delay between messages, or customize the topic and other settings as needed.

MQTT Stress Test

import paho.mqtt.client as mqtt
import time

Define the MQTT broker and topic

broker = ‘localhost’
topic = ‘test’

Create an MQTT client

mqtt_client = mqtt.Client()

Connect the MQTT client to the broker

mqtt_client.connect(broker)

Start sending messages to the broker

for i in range(100000):
mqtt_client.publish(topic, ‘Message {}’.format(i))
time.sleep(0.001)

Disconnect the MQTT client from the broker

mqtt_client.disconnect()