JMeter IoT testing using the MQTT Protocol: A Primer
Disclaimer: While it is possible to test IoT based on the MQTT protocol using JMeter, in most cases this solution would not be sufficient. This article does not intend to promote using JMeter for IoT testing, but to show the capabilities of JMeter and discuss the protocol.
An appropriate IoT testing solution for each scenario is something that needs to be determined per case—contact our sales team to discuss your specific needs. We plan on expanding informational content in this area in order to make the available resources for IoT testing attainable.
This article is a primer to performance testing in the realm of what’s known as the Internet of Things (IoT). The IoT deals with connecting devices, such as cars, appliances, medical devices, agricultural devices, and smart clothing (to name a few) to the internet. IoT generally refers to consumer-level devices. Industrial IoT (IIOT) is a subset of IoT, and focuses more on the supply-chain of critical industries. But for all intents and purposes, both IoT and IIOT require high availability servers.
That’s where performance testing comes into play. But keep in mind that the world of IoT, from the protocols it uses to the servers that handle it, is much different than the typical web pages and APIs being monitored. This article will explain the unique technologies being used by the IoT and how they can be performance tested.
How Devices Communicate in the IoT World
First, we need to understand what a device is and how it communicates over the network to a server. Devices usually have sensors that gather some sort of information. These can be environmental measurements, like heat or distance, just as some examples. Then, the data needs to be transmitted from the device to the server. This can be done either by radio or over wifi. Some devices communicate over TCP/IP directly to a server while others communicate to a gateway that forwards the message to the internet.
There are several protocols for transmitting the message from the device. In this post we will talk about the MQTT protocol (Message Queuing Telemetry Transport) which meets ISO IoT standards. MQTT is very prevalent and is supported by all the cloud service providers.
Bear in mind that another difference between IoT and regular web applications is that devices communicate asynchronously because they typically don’t need a response.
What’s the MQTT Protocol?
The MQTT protocol is different from the HTTP protocol. With MQTT we are sending a message to the server. The message is basically a long sequence of values with two segments: 1) a key and 2) a payload (the data). The key tells the message queue to which topic the message will be published. A topic is like a subject and is just an identifier used by queuing systems, so that it knows which subscribers will receive the message. That’s how Message Queue software systems like Kafka, Active MQ, and others work.
There are three main parts:
- a broker which is the server,
- a publisher such as a device in our case, and
- a subscriber, which can be a database system that receives the data.
Just one more word on brokers, or more precisely message brokers. Brokers have some similarities with web applications. Both receive requests and process them. But Message Brokers work differently: They receive a message over the MQTT protocol and publish it based on the topic - to the subscribers of that topic. There are several Message Queue brokers that implements the MQTT protocol, such as:
There are some differences between these implementations. However, in general, these services include a broker, a Pub/Sub message ingestion service, storage, streaming, and pipeline processing tasks to name a few.
Performance Testing IoT Using BlazeMeter
Now we can finally discuss how to set up a performance test for IoT devices. The first step is to create a script with JMeter. JMeter will test the publication of messages over MQTT, to a server hosting a broker. JMeter has a MQTT plugin that needs to be downloaded, installed, and set-up. For details on how to do this, see this guide.
Without getting into too much detail (we’ll save that for the follow-up article), you need to write two scripts. One script will be for the Publisher and the other for the Subscriber. Once you have the JMeter JMX script files ready, you can load them into a shared folder in the BlazeMeter environment. The JAR file of the special MQTT plugin must also be loaded into that shared folder. Finally, create a multi-test using both scripts in BlazeMeter. Just like any other test that you perform with BlazeMeter - it’s that easy.
Here is an example of the configuration of the test in BlazeMeter. Notice that each script is running on a different engine.
The results of the test run look like this:
As you can see, BlazeMeter can be used to conduct performance testing of IoT types of projects.
This has been a very high level introduction to IoT testing using the MQTT protocol and BlazeMeter. In the follow-up article, we will show detailed step-by-step instructions on how to actually set up a broker and create the JMeter scripts.
Getting More Information
You can reach out to BlazeMeter or it’s reseller, BlazeRunner, to get more information on Performance Testing, Continuous Testing, API monitoring, and more.