mirror of
https://github.com/wwhai/mqtt-benchmark.git
synced 2025-10-30 18:36:24 +08:00
29
README.md
29
README.md
@@ -30,6 +30,8 @@ Usage of ./mqtt-benchmark:
|
||||
Output format: text|json (default "text")
|
||||
-password string
|
||||
MQTT client password (empty if auth disabled)
|
||||
-payload string
|
||||
MQTT message payload. If empty, then payload is generated based on the size parameter
|
||||
-qos int
|
||||
QoS for published messages (default 1)
|
||||
-quiet
|
||||
@@ -75,6 +77,33 @@ Average Bandwidth (msg/sec): 6.761
|
||||
Total Bandwidth (msg/sec): 676.112
|
||||
```
|
||||
|
||||
With payload specified:
|
||||
|
||||
```sh
|
||||
> mqtt-benchmark --broker tcp://broker.local:1883 --count 100 --clients 10 --qos 1 --topic house/bedroom/temperature --payload {\"temperature\":20,\"timeStamp\":1597314150}
|
||||
....
|
||||
|
||||
======= CLIENT 0 =======
|
||||
Ratio: 1.000 (100/100)
|
||||
Runtime (s): 0.725
|
||||
Msg time min (ms): 1.999
|
||||
Msg time max (ms): 22.997
|
||||
Msg time mean (ms): 6.955
|
||||
Msg time std (ms): 3.523
|
||||
Bandwidth (msg/sec): 137.839
|
||||
|
||||
========= TOTAL (1) =========
|
||||
Total Ratio: 1.000 (100/100)
|
||||
Total Runtime (sec): 0.736
|
||||
Average Runtime (sec): 0.725
|
||||
Msg time min (ms): 1.999
|
||||
Msg time max (ms): 22.997
|
||||
Msg time mean mean (ms): 6.955
|
||||
Msg time mean std (ms): 0.000
|
||||
Average Bandwidth (msg/sec): 137.839
|
||||
Total Bandwidth (msg/sec): 137.839
|
||||
```
|
||||
|
||||
Similarly, in JSON:
|
||||
|
||||
```json
|
||||
|
||||
15
client.go
15
client.go
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GaryBoone/GoStats/stats"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
)
|
||||
|
||||
@@ -18,6 +19,7 @@ type Client struct {
|
||||
BrokerUser string
|
||||
BrokerPass string
|
||||
MsgTopic string
|
||||
MsgPayload string
|
||||
MsgSize int
|
||||
MsgCount int
|
||||
MsgQoS byte
|
||||
@@ -74,13 +76,20 @@ func (c *Client) Run(res chan *RunResults) {
|
||||
}
|
||||
|
||||
func (c *Client) genMessages(ch chan *Message, done chan bool) {
|
||||
for i := 0; i < c.MsgCount; i++ {
|
||||
var payload interface{}
|
||||
// set payload if specified
|
||||
if c.MsgPayload != "" {
|
||||
payload = c.MsgPayload
|
||||
} else {
|
||||
payload = make([]byte, c.MsgSize)
|
||||
}
|
||||
|
||||
ch <- &Message{
|
||||
Topic: c.MsgTopic,
|
||||
QoS: c.MsgQoS,
|
||||
Payload: make([]byte, c.MsgSize),
|
||||
}
|
||||
Payload: payload,
|
||||
}
|
||||
|
||||
done <- true
|
||||
// log.Printf("CLIENT %v is done generating messages\n", c.ID)
|
||||
return
|
||||
|
||||
2
main.go
2
main.go
@@ -60,6 +60,7 @@ func main() {
|
||||
var (
|
||||
broker = flag.String("broker", "tcp://localhost:1883", "MQTT broker endpoint as scheme://host:port")
|
||||
topic = flag.String("topic", "/test", "MQTT topic for outgoing messages")
|
||||
payload = flag.String("payload", "", "MQTT message payload. If empty, then payload is generated based on the size parameter")
|
||||
username = flag.String("username", "", "MQTT client username (empty if auth disabled)")
|
||||
password = flag.String("password", "", "MQTT client password (empty if auth disabled)")
|
||||
qos = flag.Int("qos", 1, "QoS for published messages")
|
||||
@@ -109,6 +110,7 @@ func main() {
|
||||
BrokerUser: *username,
|
||||
BrokerPass: *password,
|
||||
MsgTopic: *topic,
|
||||
MsgPayload: *payload,
|
||||
MsgSize: *size,
|
||||
MsgCount: *count,
|
||||
MsgQoS: byte(*qos),
|
||||
|
||||
Reference in New Issue
Block a user