MQTT is the lightweight, publish-subscribe messaging protocol that powers IoT devices, industrial sensors, connected vehicles, and any system where bandwidth and battery life are at a premium. Because MQTT brokers must handle thousands — sometimes millions — of simultaneous client connections, understanding their performance limits under realistic concurrent load is critical. Gatling’s dedicated MQTT SDK lets you simulate both publishers and subscribers as virtual users, measure delivery latency, and validate that messages are received with the correct Quality of Service level.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gatling/gatling.io-doc/llms.txt
Use this file to discover all available pages before exploring further.
MQTT vs HTTP in Gatling
Unlike HTTP, MQTT is a publish-subscribe protocol that does not block threads waiting for a response. Gatling does not record response times for MQTT messages by default. To measure delivery latency, you must use an explicit.expect() check that blocks the virtual user until a matching message is received on the topic.
Key metrics to monitor for MQTT load tests are found in the Connections tab of Gatling Enterprise Edition reports, which shows TCP connection open/close rates and concurrent connection counts.
Setting Up the Project
Clone the gatling/gatling-mqtt-demo repository and open the Maven Java project in your IDE. If you are adding MQTT testing to an existing project, add the following imports:Configure the MQTT Protocol
Point Gatling at your MQTT broker and set the default Quality of Service level:Write the Subscriber Scenario
The subscriber scenario connects to the broker and listens for messages on a topic. The.expect() call sets a window during which Gatling will wait for a message to arrive and record the delivery time:
Write the Publisher Scenario
The publisher connects and sends messages. Adding.expect() here validates that the broker acknowledges receipt within the specified duration:
Define the Injection Profile
In this simulation, one subscriber listens while 1,000 publishers ramp up over 30 seconds — modelling the surge of connected devices that might come online simultaneously:Complete Simulation
Adding Assertions
Add assertions to yoursetUp block to set clear pass/fail criteria for the test:
Running on Gatling Enterprise Edition
Upload your simulation to Gatling Enterprise Edition to run distributed load tests across multiple regions simultaneously. This is particularly important for IoT load tests, where you may want to simulate devices connecting from geographically diverse locations.Private Locations
If your MQTT broker is inside a private network, deploy Gatling load generators on your own infrastructure using the Private Locations feature.
Dedicated IP Addresses
If your broker is public but protected by a firewall, use Gatling Enterprise Edition’s Dedicated IP Addresses feature to whitelist the load generator IPs.
QoS Level Reference
| Level | Constant | Guarantee | Use case |
|---|---|---|---|
| 0 | qosAtMostOnce() | At most once (fire-and-forget) | Telemetry where loss is acceptable |
| 1 | qosAtLeastOnce() | At least once (may duplicate) | Most IoT sensor data |
| 2 | qosExactlyOnce() | Exactly once | Financial or critical commands |