Skip to content

MQTT Sub Sampler: Timeout Option for Sample on 'Number or received messages' #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
028e578
replace javax.xml.bind with jakarta.xml.bind dependency
br41nst0rm Jun 3, 2022
963bd41
option to set a (wait)timeout when using SAMPLE_ON_CONDITION_OPTION2
br41nst0rm Jun 3, 2022
42e294e
version update: mqtt-jmeter 2.0.3, jmeter 5.4.3
br41nst0rm Jun 3, 2022
3503098
PubSamplerUI: QoS: added JLabel; JLabeledChoice is missing a Label
br41nst0rm Jun 3, 2022
6c4fa51
back to javax.xml.bind
br41nst0rm Jun 5, 2022
3103050
imports
br41nst0rm Jun 5, 2022
88563e4
fix: use a thread local CharsetDecode instance to prevent IllegalStat…
ChangingFond Jul 4, 2022
87685c6
fix: bump jmeter version to 5.4.3 fixing critical Log4j vulnerabiliti…
DaHoC Jul 4, 2022
40747e3
Initial commit; Updating code to current dev state
erikdanielbothe Jul 13, 2022
125ee9a
Expanded and spellchecked README
erikdanielbothe Jul 13, 2022
8a32f7a
Renamed main project package
erikdanielbothe Jul 13, 2022
f04fc1b
Amended gitignore
erikdanielbothe Jul 13, 2022
f7b5db7
Removed download folder
erikdanielbothe Jul 13, 2022
1330aa1
Reverted package renaming
erikdanielbothe Jul 13, 2022
874b3af
connection option (conn name)
br41nst0rm Aug 13, 2022
7bd5eba
fix DisConnectSamplerUI (ConnOptions)
br41nst0rm Aug 13, 2022
06ec6e5
ConnectSampler: if connected try disconnect and remove connection var…
br41nst0rm Aug 13, 2022
ee5a60a
Merge branch 'master' of https://github.com/br41nst0rm/mqtt-jmeter
erikdanielbothe Aug 15, 2022
4651cf8
code refactor - all warnings and suggestions processed
br41nst0rm Aug 15, 2022
c561451
Spurious wakeups - Implemented recommended approach for obj.wait() as…
br41nst0rm Aug 16, 2022
2e02443
Update SubSampler.java - fixed if statement
br41nst0rm Dec 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
target/
.metadata/
.DS_Store
.idea/
Download/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 16 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
# mqtt-jmeter Overview
MQTT JMeter Plugin extends your JMeter's capability to test against MQTT protocol, just as easy as ordinary HTTP protocal.
MQTT JMeter Plugin extends your JMeter's capability to test against MQTT protocol, just as easy as ordinary HTTP protocol.

It has been used to benchmark EMQ server performance, and here is the [report link](https://github.com/emqx/emq-xmeter-cn).

This plugin is developed and maintained by [XMeter](https://www.xmeter.net). XMeter is a professional performance testing service provider.
The original plugin is developed by [XMeter](https://www.xmeter.net). This version of the plugin is developed by Expleo for internal usage only.

# Install instruction
The plugin is a standard JMeter plugin. You can download the latest version of mqtt-jmeter from [here](https://github.com/emqx/mqtt-jmeter/releases), and then copy the downloaded JAR files into $JMETER_HOME/lib/ext folder. After restarting the JMeter, you can see "MQTT samplers" provided by this plugin.
The plugin is a standard JMeter plugin. To use it, clone the project and run 'mvn install'. Maven will download some JMeter dependencies, so build time may depend on your network connection. Find the resulting JAR file (usually ending with '\[...\]-with-dependencies') in the target and copy it into $JMETER_HOME/lib/ext folder. After restarting JMeter, you can see "MQTT samplers" provided by this plugin.

To use this plugin, we recommend you to install JMeter 3.2 or above.

## Build from source code

If you'd like to build binary by yourself, please clone the project and run 'mvn install'. Maven will download some JMeter dependency binary files, so the build elapsed time will up to your network status.

# How to use
The plugin includes 4 samplers:

- Connect sampler: Initiate MQTT server connection on behalf of a device. In addition to normal connection setup, this sampler can be used to simulate massive "background" connections(no data transimission but regular hearbeat signals) to the designated MQTT server or cluster system.
- Connect sampler: Initiate MQTT server connection on behalf of a device. In addition to normal connection setup, this sampler can be used to simulate massive "background" connections (no data transmission but regular heartbeat signals) to the designated MQTT server or cluster system.

- Pub sampler: publish various messages to the target MQTT server.

- Sub sampler: subscribe message(s) from target MQTT server.
- Sub sampler: subscribe to topics on target MQTT server and receive messages from the server.

- DisConnect sampler: Reset the connection to target MQTT server.

If MQTT JMeter plugin is successfully installed, you can find these MQTT samplers under JMeter 'Sampler' context menu.

![mqtt_jmeter_plugin](screenshots/mqtt_jmeter_plugin.png)


## Connect Sampler
![conn_sampler](screenshots/conn_sampler.png)

Expand All @@ -39,13 +34,12 @@ This section includes basic connection settings.

- **Server name or IP**: The MQTT target to be tested. It can be either IP address or server name. The default value is 127.0.0.1. **DO NOT** add protocol (e.g. tcp:// or ssl://) before server name or IP address!

- **Port number**: The port opened by MQTT server. Typically 1883 is for TCP protocol, and 8883 for SSL protocol.
- **Port number**: The port opened by MQTT server. Typically, 1883 is for TCP protocol, and 8883 for SSL protocol.

- **MQTT version**: The MQTT version, default is 3.1, and another option is 3.1.1. Sometimes we found version 3.1.1 is required to establish connection to [Azure IoTHub](https://github.com/emqx/mqtt-jmeter/issues/21).
- **MQTT version**: The MQTT version, default is 3.1, and another option is 3.1.1. We found that sometimes version 3.1.1 is required to establish connection to [Azure IoTHub](https://github.com/emqx/mqtt-jmeter/issues/21).

- **Timeout(s)**: The connection timeout seconds while connecting to MQTT server. The default is 10 seconds.


### MQTT Protocol

The sampler supports 4 protocols, TCP, SSL, WS, WSS.
Expand All @@ -57,18 +51,18 @@ If **'Dual SSL authentication'** is checked, please follow 'Certification files

### User authentication

User can configure MQTT server with user name & password authentication, refer to [EMQ user name and password authentication guide](http://emqtt.com/docs/v2/guide.html#id3).
User can configure MQTT server with username & password authentication, refer to [EMQ user name and password authentication guide](http://emqtt.com/docs/v2/guide.html#id3).

- **User name**: If MQTT server is configured with user name, then specify user name here.
- **Username**: If MQTT server is configured with username, then specify username here.

- **Password**: If MQTT server is configured with password, then specify password here.

### Connection options

- **ClientId**: Identification of the client, i.e. virtual user or JMeter thread. Default value is 'conn_'. If 'Add random client id suffix' is selected, JMeter plugin will append generated uuid as suffix to represent the client, otherwise, the text of 'ClientId' will be passed as 'clientId' of current connection.
- **Keep alive(s)**: Ping packet send interval in seconds. Default value is 300, which means each connection sends a ping packet to MQTT server every 5 minutes.
- **Connect attampt max**: The maximum number of reconnect attempts before an error is reported back to the client on the first attempt by the client to connect to a server. Set to -1 to use unlimited attempts. Defaults to 0.
- **Reconnect attampt max**: The maximum number of reconnect attempts before an error is reported back to the client after a server connection had previously been established. Set to -1 to use unlimited attempts. Defaults to 0.
- **Connect attempt max**: The maximum number of reconnect attempts before an error is reported back to the client on the first attempt by the client to connect to a server. Set to -1 to use unlimited attempts. Defaults to 0.
- **Reconnect attempt max**: The maximum number of reconnect attempts before an error is reported back to the client after a server connection had previously been established. Set to -1 to use unlimited attempts. Defaults to 0.
- **Clean session**: If you want to maintain state information between sessions, set it to false; otherwise, set it to true.


Expand Down Expand Up @@ -108,32 +102,31 @@ Sub sampler reuses previously established connection (by Connect sampler) to sub

- **Topic name(s)**: A list of topic names (comma-separated) that will be subscribed to.

- **Payload includes timestamp**: If the checkbox is enabled, then it means the payload includes timestamp. It can be used to calcuate the message latency time.
- **Payload includes timestamp**: If the checkbox is enabled, then it means the payload includes timestamp. It can be used to calculate the message latency time.

```
message_latency = timestamp_in_sub_when_receive_msg - timestamp_in_payload (timestamp in pub machine when sending out message)

Please notice, if the machine publish message is not the same as subscriber, then the calculated message latency time is not accurate.
It's because the time is almost not the same in different machines. So the latency time calculated by sub sampler could be only be a reference.
```
- **Sample on**: It controls how to sample. The default value is '**elapsed with specified time(ms)**', which means a sub sampler will occur every specified milli-seconds (default is 1000ms). During the 1000 ms, multiple messages could be received, and result in report is the summarized data during 1000 ms. If the value is set to 2000, then means summarized report during 2000 ms. Another option is '**number of received messages**', which means a sub sampler will occur after receiving these specified number of messages (default is 1).
- **Sample on**: It controls how to sample. The default value is '**elapsed with specified time(ms)**', which means a sub sampler will occur every specified milli-seconds (default is 1000ms). During the 1000 ms, multiple messages could be received, and result in report is the summarized data during 1000 ms. If the value is set to 2000, then means summarized report during 2000 ms. Another option is '**number of received messages**', which means a sub sampler will occur after receiving these specified number of messages (default is 1).

- **Debug response**: If checked, the received message will be print in response. It's recommended to enable this option when you debug your script.


## DisConnect Sampler
![disconn_sampler](screenshots/disconn_sampler.png)

This sampler is very simple, it just clear the previous created connection. Therefore, next time you run Connect sampler, it will initiate a new MQTT server connection for you. As you can imagine, Disconnect sample will fail immediately if no connection is detected at this moment.

This sampler is very simple, it just clears the previous created connection. Therefore, next time you run Connect sampler, it will initiate a new MQTT server connection for you. As you can imagine, Disconnect sample will fail immediately if no connection is detected at this moment.

## Example JMeter Scripts
As a reference, you can check out some example scripts in SampleScripts folder.
1) background_connection.jmx:
Simulate massive background MQTT connections to server. You can optionally subscribe to a topic when connecting. (Please modify "xmeter_runtime_vars" UDV to fit your needs.)

2) pubsub_unidirection.jmx:
Demonstrate how sub sampler can get messages from corresponding pub sampler, with two JMeter user groups and delay between opertions.
Demonstrate how sub sampler can get messages from corresponding pub sampler, with two JMeter user groups and delay between operations.

3) pubsub_bidirection.jmx:
Demonstrate how a set of Devices and Mobiles exchange messages in both directions.
Expand All @@ -153,7 +146,7 @@ After deploying emqtt server, you get the following OOTB (out of the box) SSL/TL

[Note:] The above server and client certifications are both issued by the self-signed CA. If you would like to use official certifications for your EMQTT deployment, please check out relevant document to configure it.

We will use the OOTB test certfications (as an example) to show you how to prepare the required certification files for this EMQTT JMeter plugin.
We will use the OOTB test certifications (as an example) to show you how to prepare the required certification files for this EMQTT JMeter plugin.

```
export PATH=$PATH:<YOUR_JDK_HOME>/bin
Expand Down
20 changes: 13 additions & 7 deletions mqtt_jmeter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.xmeter</groupId>
<artifactId>mqtt-jmeter</artifactId>
<version>2.0.2</version>
<version>2.0.3</version>

<properties>
<jmeter-version>5.0</jmeter-version>
<jmeter-version>5.4.3</jmeter-version>
</properties>

<dependencies>
Expand All @@ -27,28 +27,34 @@
<dependency>
<groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId>
<version>1.14</version>
<version>1.16</version>
</dependency>

<dependency>
<groupId>com.hivemq</groupId>
<artifactId>hivemq-mqtt-client</artifactId>
<version>1.1.3</version>
<version>1.3.0</version>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>

</dependencies>

<build>
<finalName>mqtt-xmeter-${project.version}</finalName>
<finalName>plugin-xmeter-${project.version}</finalName>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@

public class AcceptAllTrustManagerFactory extends TrustManagerFactory {

private static final Provider PROVIDER = new Provider("", 0.0, "") {
private static final Provider PROVIDER = new Provider("", "0.0", "") {
private static final long serialVersionUID = -2226165055935321223L;
};

private AcceptAllTrustManagerFactory() {
super(AcceptAllTrustManagerFactorySpi.getInstance(), PROVIDER, "");
}

public static final TrustManagerFactory getInstance() {
public static TrustManagerFactory getInstance() {
return new AcceptAllTrustManagerFactory();
}

static final class AcceptAllTrustManagerFactorySpi extends TrustManagerFactorySpi {

public static final AcceptAllTrustManagerFactorySpi getInstance() {
public static AcceptAllTrustManagerFactorySpi getInstance() {
return new AcceptAllTrustManagerFactorySpi();
}

Expand Down
Loading