ThingsBoard MQTT Load Test With Gatling

Juniarto Samsudin
2 min readSep 25, 2019

Gatling is a load test framework, very similar to Apache-JMeter, plus steroid. The test report page is exquisite, pleasing to the eye. If you want to impress your boss with your application load-test report, you can score better using Gatling rather than JMeter.

Installation

As of this writing, the latest release is 3.2.1. But don’t use this version, use version 2.2.3 . The latest version is not compatible with unofficial-mqqt-plugin.

  1. Get Gatling 2.2.3
$wget https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/2.2.3/gatling-charts-highcharts-bundle-2.2.3-bundle.zip$unzip gatling-charts-highcharts-bundle-2.2.3-bundle.zip

2. Get Unofficial MQTT Plugin for Gatling

a. Cloning the repository
$ git clone https://github.com/thingsboard/gatling-mqtt.git
$ cd gatling-mqtt
b. Install Scala
$ sudo apt-get remove scala-library scala
$ sudo wget http://scala-lang.org/files/archive/scala-2.11.8.deb
$ sudo dpkg -i scala-2.11.8.deb
c. Install sbt
$echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
$curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
$sudo apt-get update
$sudo apt-get install sbt
d. Create jar file
$sbt assembly
e. Moving the jar file to lib directory
$ cp target/scala-2.11/gatling-mqtt-assembly-*.jar /path/to/gatling-charts-highcharts-bundle-2.2.*/lib
f. Creating a simulation file
$ cp gatling-mqtt/src/test/scala/com/github/mnogu/gatling/mqtt/test/MqttSimulation.scala /path/to/gatling-charts-highcharts-bundle-2.2.*/user-files/simulations
$ cd /path/to/gatling-charts-highcharts-bundle-2.2.*
$ vi user-files/simulations/MqttSimulation.scala

3. Simulation file sample to connect to ThingsBoard device

package com.github.mnogu.gatling.mqtt.testimport com.github.mnogu.gatling.mqtt.Predef._
import io.gatling.core.Predef._
import org.fusesource.mqtt.client.QoS
import scala.concurrent.duration._class MqttSimulation extends Simulation {
val mqttConf = mqtt
.host("tcp://thingsboard_ip_address:1883")
.userName("gGK3JTtol0gkcWdAbjjg")
.password("gGK3JTtol0gkcWdAbjjg")
val connect = exec(mqtt("connect")
.connect())
val publish = repeat(50) {
exec(mqtt("publish")
.publish("v1/devices/me/telemetry", "{\"temp\":73.2}",QoS.AT_LEAST_ONCE, retain = false))
.pause(100 milliseconds)
}
val disconnect = exec(mqtt("disconnect")
.disconnect())
val scn = scenario("MQTT Test")
.exec(connect, publish, disconnect)
setUp(
scn
.inject(rampUsers(1) over (1 seconds))
).protocols(mqttConf)
}

4. Install NGINX and point it to your Gatlin — Result Directory

root /home/ubuntu/gatling-charts-highcharts-bundle-2.2.3/results;# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
autoindex on;
}

--

--