• Stars
    star
    511
  • Rank 86,452 (Top 2 %)
  • Language
    Erlang
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated 23 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight MQTT benchmark tool written in Erlang

Lightweight MQTT Benchmark Tool written in Erlang

image

eMQTT-Bench is a lightweight MQTT v5.0 benchmark tool written in Erlang.

You can download pre-built binary packeges from https://github.com/emqx/emqtt-bench/releases.

Build from source code

NOTE: Requires Erlang/OTP 22.3+ to build.

Install dependencies

emqtt-bench requires libatomic

# centos 7
sudo yum install libatomic
# ubuntu 20.04
sudo apt install libatomic1 

make

git clone https://github.com/emqx/emqtt-bench.git
cd emqtt-bench
make

Optional, you could disable QUIC support if you have problem with compiling

BUILD_WITHOUT_QUIC=1 make

Connect Benchmark

$ ./emqtt_bench conn --help
Usage: emqtt_bench conn [--help <help>] [-d <dist>] [-h [<host>]]
                        [-p [<port>]] [-V [<version>]] [-c [<count>]]
                        [-n [<startnumber>]] [--load-qst <nst_dets_file>]
                        [-Q [<qoe>]] [-i [<interval>]] [-u <username>]
                        [-P <password>] [-k [<keepalive>]] [-C [<clean>]]
                        [-x [<expiry>]] [-S [<ssl>]]
                        [--certfile <certfile>] [--keyfile <keyfile>]
                        [--quic [<quic>]] [--ifaddr <ifaddr>]
                        [--prefix <prefix>] [-s [<shortids>]]
                        [-l <lowmem>]
                        [--num-retry-connect [<num_retry_connect>]]
                        [-R [<conn_rate>]]
                        [--force-major-gc-interval [<force_major_gc_interval>]]
                        [--log_to [<log_to>]]

  --help                     help information
  -d, --dist                 enable distribution port
  -h, --host                 mqtt server hostname or comma-separated 
                             hostnames [default: localhost]
  -p, --port                 mqtt server port number [default: 1883]
  -V, --version              mqtt protocol version: 3 | 4 | 5 [default: 5]
  -c, --count                max count of clients [default: 200]
  -n, --startnumber          start number [default: 0]
  -Q, --qoe                  Enable QoE tracking [default: false]
  -i, --interval             interval of connecting to the broker 
                             [default: 10]
  -u, --username             username for connecting to server
  -P, --password             password for connecting to server
  -k, --keepalive            keep alive in seconds [default: 300]
  -C, --clean                clean session [default: true]
  -x, --session-expiry       Set 'Session-Expiry' for persistent sessions 
                             (seconds) [default: 0]
  -S, --ssl                  ssl socoket for connecting to server 
                             [default: false]
  --certfile                 client certificate for authentication, if 
                             required by server
  --keyfile                  client private key for authentication, if 
                             required by server
  --quic                     QUIC transport [default: false]
  --load-qst                 load quic session tickets from dets file
  --ifaddr                   local ipaddress or interface address
  --prefix                   client id prefix
  -s, --shortids             use short ids for client ids [default: false]
  -l, --lowmem               enable low mem mode, but use more CPU
  --num-retry-connect        number of times to retry estabilishing a 
                             connection before giving up [default: 0]
  -R, --connrate             connection rate(/s), default: 0, fallback to 
                             use --interval [default: 0]
  --force-major-gc-interval  interval in milliseconds in which a major GC 
                             will be forced on the bench processes.  a 
                             value of 0 means disabled (default).  this 
                             only takes effect when used together with 
                             --lowmem. [default: 0]
  --log_to                   Control where the log output goes. console: 
                             directly to the console      null: quietly, 
                             don't output any logs. [default: console]

For example, create 50K concurrent connections at the arrival rate of 100/sec:

./emqtt_bench conn -c 50000 -i 10

Sub Benchmark

$ ./emqtt_bench sub --help
Usage: emqtt_bench sub [--help <help>] [-d <dist>] [-h [<host>]] [-p [<port>]] [-V [<version>]] [-c [<count>]]
                       [-n [<startnumber>]] [-i [<interval>]] [-t <topic>] [--payload-hdrs [<payload_hdrs>]] [-q [<qos>]]
                       [-Q [<qoe>]] [-u <username>] [-P <password>] [-k [<keepalive>]] [-C [<clean>]] [-x [<expiry>]]
                       [-S [<ssl>]] [--certfile <certfile>] [--keyfile <keyfile>] [--ws [<ws>]] [--quic [<quic>]]
                       [--load-qst <nst_dets_file>] [--ifaddr <ifaddr>] [--prefix <prefix>] [-s [<shortids>]] [-l <lowmem>]
                       [--num-retry-connect [<num_retry_connect>]] [-R [<conn_rate>]]
                       [--force-major-gc-interval [<force_major_gc_interval>]] [--log_to [<log_to>]]

  --help                     help information
  -d, --dist                 enable distribution port
  -h, --host                 mqtt server hostname or comma-separated hostnames [default: localhost]
  -p, --port                 mqtt server port number [default: 1883]
  -V, --version              mqtt protocol version: 3 | 4 | 5 [default: 5]
  -c, --count                max count of clients [default: 200]
  -n, --startnumber          The start point when assigning sequence numbers to clients. This is useful when running 
                             multiple emqtt-bench instances to test the same broker (cluster), so the start number can be 
                             planned to avoid client ID collision [default: 0]
  -i, --interval             interval of connecting to the broker [default: 10]
  -t, --topic                topic subscribe, support %u, %c, %i variables
  --payload-hdrs             Handle the payload header from received message. Publish side must have the same option enabled 
                             in the same order. cnt64: Check the counter is strictly increasing. ts: publish latency counting. 
                             [default: ]
  -q, --qos                  subscribe qos [default: 0]
  -Q, --qoe                  Enable QoE tracking [default: false]
  -u, --username             username for connecting to server
  -P, --password             password for connecting to server
  -k, --keepalive            keep alive in seconds [default: 300]
  -C, --clean                clean start [default: true]
  -x, --session-expiry       Set 'Session-Expiry' for persistent sessions (seconds) [default: 0]
  -S, --ssl                  ssl socoket for connecting to server [default: false]
  --certfile                 client certificate for authentication, if required by server
  --keyfile                  client private key for authentication, if required by server
  --ws                       websocket transport [default: false]
  --quic                     QUIC transport [default: false]
  --load-qst                 load quic session tickets from dets file
  --ifaddr                   local ipaddress or interface address
  --prefix                   Client ID prefix. If not provided '$HOST_bench_(pub|sub)_$RANDOM_$N' is used, where $HOST is 
                             either the host name or the IP address provided in the --ifaddr option, $RANDOM is a random 
                             number and $N is the sequence number assigned for each client. If provided, the $RANDOM suffix 
                             will not be added.
  -s, --shortids             Use short client ID. If --prefix is provided, the prefix is added otherwise client ID is the 
                             assigned sequence number. [default: false]
  -l, --lowmem               enable low mem mode, but use more CPU
  --num-retry-connect        number of times to retry estabilishing a connection before giving up [default: 0]
  -R, --connrate             connection rate(/s), default: 0, fallback to use --interval [default: 0]
  --force-major-gc-interval  interval in milliseconds in which a major GC will be forced on the bench processes.  a value of 
                             0 means disabled (default).  this only takes effect when used together with --lowmem. [default: 
                             0]
  --log_to                   Control where the log output goes. console: directly to the console      null: quietly, don't 
                             output any logs. [default: console]

For example, create 50K concurrent connections at the arrival rate of 100/sec:

./emqtt_bench sub -c 50000 -i 10 -t bench/%i -q 2

Pub Benchmark

Usage: emqtt_bench pub [--help <help>] [-d <dist>] [-h [<host>]] [-p [<port>]] [-V [<version>]] [-c [<count>]]
                       [-n [<startnumber>]] [-i [<interval>]] [-I [<interval_of_msg>]] [-u <username>] [-P <password>]
                       [-t <topic>] [--payload-hdrs [<payload_hdrs>]] [-s [<size>]] [-m <message>] [-q [<qos>]]
                       [-Q [<qoe>]] [-r [<retain>]] [-k [<keepalive>]] [-C [<clean>]] [-x [<expiry>]] [-L [<limit>]]
                       [-S [<ssl>]] [--certfile <certfile>] [--keyfile <keyfile>] [--ws [<ws>]] [--quic [<quic>]]
                       [--load-qst <nst_dets_file>] [--ifaddr <ifaddr>] [--prefix <prefix>] [-s [<shortids>]] [-l <lowmem>]
                       [-F [<inflight>]] [-w [<wait_before_publishing>]] [--max-random-wait [<max_random_wait>]]
                       [--min-random-wait [<min_random_wait>]] [--num-retry-connect [<num_retry_connect>]]
                       [-R [<conn_rate>]] [--force-major-gc-interval [<force_major_gc_interval>]] [--log_to [<log_to>]]

  --help                        help information
  -d, --dist                    enable distribution port
  -h, --host                    mqtt server hostname or comma-separated hostnames [default: localhost]
  -p, --port                    mqtt server port number [default: 1883]
  -V, --version                 mqtt protocol version: 3 | 4 | 5 [default: 5]
  -c, --count                   max count of clients [default: 200]
  -n, --startnumber             The start point when assigning sequence numbers to clients. This is useful when running 
                                multiple emqtt-bench instances to test the same broker (cluster), so the start number can be 
                                planned to avoid client ID collision [default: 0]
  -i, --interval                interval of connecting to the broker [default: 10]
  -I, --interval_of_msg         interval of publishing message(ms) [default: 1000]
  -u, --username                username for connecting to server
  -P, --password                password for connecting to server
  -t, --topic                   topic subscribe, support %u, %c, %i, %s variables
  --payload-hdrs                 If set, add optional payload headers. cnt64: strictly increasing counter(64bit) per publisher 
                                ts: Timestamp when emit example: --payload-hdrs cnt64,ts [default: ]
  -s, --size                    payload size [default: 256]
  -m, --message                 set the message content for publish
  -q, --qos                     subscribe qos [default: 0]
  -Q, --qoe                     Enable QoE tracking [default: false]
  -r, --retain                  retain message [default: false]
  -k, --keepalive               keep alive in seconds [default: 300]
  -C, --clean                   clean start [default: true]
  -x, --session-expiry          Set 'Session-Expiry' for persistent sessions (seconds) [default: 0]
  -L, --limit                   The max message count to publish, 0 means unlimited [default: 0]
  -S, --ssl                     ssl socoket for connecting to server [default: false]
  --certfile                    client certificate for authentication, if required by server
  --keyfile                     client private key for authentication, if required by server
  --ws                          websocket transport [default: false]
  --quic                        QUIC transport [default: false]
  --load-qst                    load quic session tickets from dets file
  --ifaddr                      One or multiple (comma-separated) source IP addresses
  --prefix                      Client ID prefix. If not provided '$HOST_bench_(pub|sub)_$RANDOM_$N' is used, where $HOST is 
                                either the host name or the IP address provided in the --ifaddr option, $RANDOM is a random 
                                number and $N is the sequence number assigned for each client. If provided, the $RANDOM 
                                suffix will not be added.
  -s, --shortids                Use short client ID. If --prefix is provided, the prefix is added otherwise client ID is the 
                                assigned sequence number. [default: false]
  -l, --lowmem                  enable low mem mode, but use more CPU
  -F, --inflight                maximum inflight messages for QoS 1 an 2, value 0 for 'infinity' [default: 1]
  -w, --wait-before-publishing  wait for all publishers to have (at least tried to) connected before starting publishing 
                                [default: false]
  --max-random-wait             maximum randomized period in ms that each publisher will wait before starting to publish 
                                (uniform distribution) [default: 0]
  --min-random-wait             minimum randomized period in ms that each publisher will wait before starting to publish 
                                (uniform distribution) [default: 0]
  --num-retry-connect           number of times to retry estabilishing a connection before giving up [default: 0]
  -R, --connrate                connection rate(/s), default: 0, fallback to use --interval [default: 0]
  --force-major-gc-interval     interval in milliseconds in which a major GC will be forced on the bench processes.  a value 
                                of 0 means disabled (default).  this only takes effect when used together with --lowmem. 
                                [default: 0]
  --log_to                      Control where the log output goes. console: directly to the console      null: quietly, 
                                don't output any logs. [default: console]

For example, create 100 connections and each publishes messages at the rate of 100 msg/sec.

./emqtt_bench pub -c 100 -I 10 -t bench/%i -s 256

Local interface

./emqtt_bench pub --ifaddr 192.168.1.10
./emqtt_bench sub --ifaddr 192.168.2.10

TLS/SSL (cliet certificate is not required by server)

./emqtt_bench sub -c 100 -i 10 -t bench/%i -p 8883 --ssl
./emqtt_bench pub -c 100 -I 10 -t bench/%i -p 8883 -s 256 --ssl

TLS/SSL (client certificate is required by server)

./emqtt_bench sub -c 100 -i 10 -t bench/%i -p 8883 --ssl --certfile path/to/client-cert.pem --keyfile path/to/client-key.pem
./emqtt_bench pub -c 100 -i 10 -t bench/%i -s 256 -p 8883 --ssl --certfile path/to/client-cert.pem --keyfile path/to/client-key.pem

Notice

You should not set '-c' option more than 64K for TCP ports limit on one source addresses, however you can send messages from multiple source IP Addresses with '--ifaddr ' such like

./emqtt_bench sub -c 200000 -t "perf/test" --ifaddr 192.168.200.18,192.168.200.19,192.168.200.20,192.168.200.21

Make sure to increase resource usage limits and expand the port range like following on Linux.

ulimit -n 200000
sudo sysctl -w net.ipv4.ip_local_port_range="1025 65534"

Author

EMQX Team.

More Repositories

1

emqx

The most scalable open-source MQTT broker for IoT, IIoT, and connected vehicles
Erlang
13,975
star
2

MQTTX

A Powerful and All-in-One MQTT 5.0 client toolbox for Desktop, CLI and WebSocket.
TypeScript
3,843
star
3

CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
Swift
1,589
star
4

neuron

Open source industrial IoT connectivity server
C
1,023
star
5

MQTT-Client-Examples

MQTT Client Examples
Kotlin
743
star
6

qmqtt

MQTT client for Qt
C++
679
star
7

mqtt-jmeter

MQTT JMeter Plugin
Java
438
star
8

emqtt

Erlang MQTT 5.0 Client
Erlang
365
star
9

quic

QUIC protocol for Erlang & Elixir
Erlang
220
star
10

emqx-operator

A Kubernetes Operator for EMQX
Go
209
star
11

esockd

Erlang general non-blocking TCP/SSL socket server
Erlang
199
star
12

emqx-rel

Release Project for EMQX Broker prior to 4.3. Newer releases are built here: https://github.com/emqx/emqx
Shell
189
star
13

emqx-docs

EMQX product documentation
HTML
156
star
14

NanoSDK

NanoSDK - MQTT 5.0-compliant SDK with QUIC support in NNG flavor
C
126
star
15

mria

Asynchronously replicated Mnesia-like database for Erlang/Elixir
Erlang
117
star
16

qmqtt-client

MQTT Client GUI Written with Qt
C++
97
star
17

ekka

Autocluster and Autoheal for EMQX Broker
Erlang
94
star
18

emqx-web-hook

EMQX Webhook Plugin
Erlang
79
star
19

emqx-rule-engine

EMQX Rule Engine
Erlang
69
star
20

emqx-plugin-template

EMQ X Plugin Template and Demo
Erlang
63
star
21

emqx-coap

EMQX CoAP Gateway
Erlang
61
star
22

emqx-auth-mysql

Authentication, ACL with MySQL Database
Erlang
55
star
23

emqx-dashboard

EMQ X Dashboard
CSS
52
star
24

MQTT-Web-Toolkit

EMQ Web Toolkit
Vue
44
star
25

emqx-extension-examples

Examples for ExHook & ExProto
Erlang
44
star
26

emqx-auth-http

EMQX HTTP Authentication/ACL Plugin
Erlang
43
star
27

emqx-dashboard5

The management console used to monitor and manage EMQX clusters.
Vue
42
star
28

neuron-dashboard

Neuron Dashboard
TypeScript
41
star
29

minirest

A Mini RESTful API Framework
Erlang
37
star
30

emqx-bridge-mqtt

Bridge of MQTT (deprecated since EMQX v5)
Erlang
37
star
31

replayq

Generic on-disk persistent queue implementation for Erlang
Erlang
35
star
32

emqx-auth-pgsql

EMQ X PostgreSQL Authentication Plugin
Erlang
35
star
33

edge-stack

Shell
34
star
34

emqx-auth-redis

EMQ X Redis Authentication/ACL Plugin
Erlang
33
star
35

hocon

HOCON configuration Parser for Erlang/OTP
Erlang
32
star
36

mqttbs

MQTT Benchmark Suite
32
star
37

mqtt5.0-cn

MQTT Version 5.0 Chinese
31
star
38

emqx-docker

An Open-Source, Cloud-Native, Distributed MQTT Message Broker for IoT.
Shell
30
star
39

emqx-lwm2m

EMQ X LwM2M Gateway
Erlang
30
star
40

emqx-sn

EMQX MQTT-SN Gateway
Erlang
29
star
41

emqx-auth-jwt

EMQ X JWT Authentication Plugin
Erlang
28
star
42

emqx-lua-hook

EMQ X Lua Hook
Erlang
28
star
43

ecpool

Erlang Connection/Client Pool Library
Erlang
28
star
44

emqx-exporter

Prometheus exporter for EMQX
Python
26
star
45

emqx-dashboard-frontend

EMQ X Dashboard Frontend
Vue
25
star
46

emqx-prometheus

EMQX Statsd
Erlang
24
star
47

emqx-exhook

The Multiple-Language extension plugin for EMQ X Hooks
Erlang
23
star
48

blog

EMQ Blog
Python
22
star
49

emqx-retainer

EMQ X Retainer
Erlang
21
star
50

emqx-auth-mongo

EMQ X Authentication/ACL with MongoDB
Erlang
21
star
51

coap-jmeter

CoAP JMeter Plugin
Java
20
star
52

eip

EMQX Improvement Proposals
Makefile
19
star
53

emqx-elixir-plugin

An Example Plugin for EMQX in Elixir
Elixir
19
star
54

emqx-exproto

The Multiple-Language extension plugin for Protocol access
Erlang
18
star
55

openai-mqtt-nodejs

Node.js project that combines OpenAI's API with MQTT for real-time AI-driven interactions in IoT ecosystems.
JavaScript
18
star
56

emqx-auth-username

EMQ X Authentication with Username and Password
Erlang
17
star
57

mqtt-to-timescaledb

Ingesting time series data into TimescaleDB using MQTT and EMQX | MQTT Timescale Integration
Makefile
16
star
58

erlang-rocksdb

Upstream is here: https://gitlab.com/barrel-db/erlang-rocksdb
C++
16
star
59

emqx-auth-clientid

EMQ X ClientId Authentication Plugin
Erlang
16
star
60

jq

jq (nif) for beam
C
15
star
61

emqx-dashboard-web

Frontend Source Code for EMQ X dashboard Enterprise v4
Vue
15
star
62

emqx-tutorial-cn

EMQ X 中文Tutorial
14
star
63

emqx-extension-java-sdk

The Java SDK for emqx-extension-hook
Java
14
star
64

emqttb

A scriptable autotuning load generator for MQTT
Erlang
14
star
65

neuron-docs

Neuron Documentation
Shell
14
star
66

emqx-extension-python-sdk

The Python SDK for emqx-extension-hook
Python
13
star
67

HBridge

High-performance MQTT Bridge written in Haskell
Haskell
12
star
68

cdk-emqx-cluster

Python
11
star
69

pulsar-client-erl

Apache Pulsar client for Erlang/Elixir
Erlang
11
star
70

emqx-management

EMQ X Management API
Erlang
10
star
71

wormhole

The channel for routing request from cloud to edge.
Go
10
star
72

local-storage-encryption

Obfuscate key-value pairs in localStorage.
JavaScript
10
star
73

deploy-emqx-to-aws-with-terraform

HCL
10
star
74

mqtt-to-kafka

Streaming IoT data into Confluent/Kafka using MQTT and EMQX | MQTT Kafka Integration
Makefile
10
star
75

emqx-ui

EMQX UI Library
Vue
9
star
76

cloud-docs

EMQX Cloud Documentations
CSS
9
star
77

emqx-meter-cn

EMQ X Meter Benchmark
Python
9
star
78

emqx-usage-example

Using Docker Compose to show different usages of EMQX
9
star
79

mqtt-to-influxdb

Ingesting time series data into InfluxDB using MQTT and EMQX | MQTT InfluxDB Integration
JavaScript
8
star
80

example

EMQ x IoT project sample code
Java
8
star
81

ehttpc

HTTP Client for Erlang/OTP
Erlang
7
star
82

mqtt-security-scanner

MQTT Security Scanner
Go
7
star
83

rebar3_emqx_plugin

A rebar3 plugin for automatically generate emqx plugin template
Erlang
7
star
84

ipqueue

High Performance Interleaved Priority Queue for Erlang/Elixir
Erlang
7
star
85

ecql

Erlang Cassandra CQL Driver
Erlang
7
star
86

deploy-emqx-to-alibabacloud-with-terraform

HCL
6
star
87

influxdb-client-erl

Erlang
6
star
88

lc

Load Control for beam
Erlang
6
star
89

emqx-recon

Recon debug/optimize plugin
Erlang
6
star
90

tf-emqx-performance-test

HCL
6
star
91

emqx-builder

Dockerfile
5
star
92

emqx-reloader

Erlang Module Reloader
Erlang
5
star
93

emqx-exproto-java-sdk

The Java SDK for emqx-exproto
Java
5
star
94

emqx-stomp

EMQ X Stomp Protocol Plugin
Erlang
5
star
95

emqx-webinars

Webinar materials
Shell
5
star
96

bootcamp

The learning center of EMQ products
C
5
star
97

mqtt-to-redis

Ingesting IoT data into Redis using MQTT and EMQX | MQTT Redis Integration
JavaScript
5
star
98

emqx-auth-ldap

EMQ X LDAP Authentication Plugin
Erlang
5
star
99

nanomq-docker

An ultra-lightweight and blazing-fast MQTT broker for IoT edge
Dockerfile
4
star
100

emqx-10million-test-cn

EMQ X 10MILLION TEST
4
star