mirror of
https://github.com/wwhai/mqtt-benchmark.git
synced 2025-10-05 15:47:19 +08:00
Renamed parameters
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
.vscode
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,6 +0,0 @@
|
|||||||
[submodule "vendor/github.com/GaryBoone/GoStats"]
|
|
||||||
path = vendor/github.com/GaryBoone/GoStats
|
|
||||||
url = git://github.com/GaryBoone/GoStats
|
|
||||||
[submodule "vendor/github.com/eclipse/paho.mqtt.golang"]
|
|
||||||
path = vendor/github.com/eclipse/paho.mqtt.golang
|
|
||||||
url = git://github.com/eclipse/paho.mqtt.golang
|
|
46
README.md
46
README.md
@@ -12,22 +12,36 @@ go get github.com/krylovsk/mqtt-benchmark
|
|||||||
The tool supports multiple concurrent clients, configurable message size, etc:
|
The tool supports multiple concurrent clients, configurable message size, etc:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
> mqtt-benchmark --help
|
$ ./mqtt-benchmark -h
|
||||||
Usage of mqtt-benchmark:
|
Usage of ./mqtt-benchmark:
|
||||||
-broker="tcp://localhost:1883": MQTT broker endpoint as scheme://host:port
|
-broker string
|
||||||
-cert="cert.pem": File path to your client certificate in PEM format
|
MQTT broker endpoint as scheme://host:port (default "tcp://localhost:1883")
|
||||||
-client-id="mqtt-benchmark": MQTT client id
|
-client-cert string
|
||||||
-clients=10: Number of clients to start
|
Path to client certificate in PEM format
|
||||||
-count=100: Number of messages to send per client
|
-client-key string
|
||||||
-format="text": Output format: text|json
|
Path to private clientKey in PEM format
|
||||||
-key="key.pem": File path to your private key in PEM format
|
-client-prefix string
|
||||||
-password="": MQTT password (empty if auth disabled)
|
MQTT client id prefix (suffixed with '-<client-num>' (default "mqtt-benchmark")
|
||||||
-qos=1: QoS for published messages
|
-clients int
|
||||||
-quiet=false : Suppress logs while running (except errors and the result)
|
Number of clients to start (default 10)
|
||||||
-size=100: Size of the messages payload (bytes)
|
-count int
|
||||||
-topic="/test": MQTT topic for incoming message
|
Number of messages to send per client (default 100)
|
||||||
-username="": MQTT username (empty if auth disabled)
|
-format string
|
||||||
-wait="60000": QoS 1 wait timeout in milliseconds (default 60000)
|
Output format: text|json (default "text")
|
||||||
|
-password string
|
||||||
|
MQTT client password (empty if auth disabled)
|
||||||
|
-qos int
|
||||||
|
QoS for published messages (default 1)
|
||||||
|
-quiet
|
||||||
|
Suppress logs while running
|
||||||
|
-size int
|
||||||
|
Size of the messages payload (bytes) (default 100)
|
||||||
|
-topic string
|
||||||
|
MQTT topic for outgoing messages (default "/test")
|
||||||
|
-username string
|
||||||
|
MQTT client username (empty if auth disabled)
|
||||||
|
-wait int
|
||||||
|
QoS 1 wait timeout in milliseconds (default 60000)
|
||||||
```
|
```
|
||||||
|
|
||||||
> NOTE: if `count=1` or `clients=1`, the sample standard deviation will be returned as `0` (convention due to the [lack of NaN support in JSON](https://tools.ietf.org/html/rfc4627#section-2.4))
|
> NOTE: if `count=1` or `clients=1`, the sample standard deviation will be returned as `0` (convention due to the [lack of NaN support in JSON](https://tools.ietf.org/html/rfc4627#section-2.4))
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Client implements an MQTT client running benchmark test
|
||||||
type Client struct {
|
type Client struct {
|
||||||
ID int
|
ID int
|
||||||
ClientID string
|
ClientID string
|
||||||
@@ -22,9 +23,10 @@ type Client struct {
|
|||||||
MsgQoS byte
|
MsgQoS byte
|
||||||
Quiet bool
|
Quiet bool
|
||||||
WaitTimeout time.Duration
|
WaitTimeout time.Duration
|
||||||
TlsConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run runs benchmark tests and writes results in the provided channel
|
||||||
func (c *Client) Run(res chan *RunResults) {
|
func (c *Client) Run(res chan *RunResults) {
|
||||||
newMsgs := make(chan *Message)
|
newMsgs := make(chan *Message)
|
||||||
pubMsgs := make(chan *Message)
|
pubMsgs := make(chan *Message)
|
||||||
@@ -137,8 +139,8 @@ func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool)
|
|||||||
opts.SetUsername(c.BrokerUser)
|
opts.SetUsername(c.BrokerUser)
|
||||||
opts.SetPassword(c.BrokerPass)
|
opts.SetPassword(c.BrokerPass)
|
||||||
}
|
}
|
||||||
if c.TlsConfig != nil {
|
if c.TLSConfig != nil {
|
||||||
opts.SetTLSConfig(c.TlsConfig)
|
opts.SetTLSConfig(c.TLSConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := mqtt.NewClient(opts)
|
client := mqtt.NewClient(opts)
|
||||||
|
28
main.go
28
main.go
@@ -60,9 +60,8 @@ func main() {
|
|||||||
var (
|
var (
|
||||||
broker = flag.String("broker", "tcp://localhost:1883", "MQTT broker endpoint as scheme://host:port")
|
broker = flag.String("broker", "tcp://localhost:1883", "MQTT broker endpoint as scheme://host:port")
|
||||||
topic = flag.String("topic", "/test", "MQTT topic for outgoing messages")
|
topic = flag.String("topic", "/test", "MQTT topic for outgoing messages")
|
||||||
clientID = flag.String("client-id", "mqtt-benchmark", "MQTT client id")
|
username = flag.String("username", "", "MQTT client username (empty if auth disabled)")
|
||||||
username = flag.String("username", "", "MQTT username (empty if auth disabled)")
|
password = flag.String("password", "", "MQTT client password (empty if auth disabled)")
|
||||||
password = flag.String("password", "", "MQTT password (empty if auth disabled)")
|
|
||||||
qos = flag.Int("qos", 1, "QoS for published messages")
|
qos = flag.Int("qos", 1, "QoS for published messages")
|
||||||
wait = flag.Int("wait", 60000, "QoS 1 wait timeout in milliseconds")
|
wait = flag.Int("wait", 60000, "QoS 1 wait timeout in milliseconds")
|
||||||
size = flag.Int("size", 100, "Size of the messages payload (bytes)")
|
size = flag.Int("size", 100, "Size of the messages payload (bytes)")
|
||||||
@@ -70,8 +69,9 @@ func main() {
|
|||||||
clients = flag.Int("clients", 10, "Number of clients to start")
|
clients = flag.Int("clients", 10, "Number of clients to start")
|
||||||
format = flag.String("format", "text", "Output format: text|json")
|
format = flag.String("format", "text", "Output format: text|json")
|
||||||
quiet = flag.Bool("quiet", false, "Suppress logs while running")
|
quiet = flag.Bool("quiet", false, "Suppress logs while running")
|
||||||
cert = flag.String("cert", "", "File path to your client certificate in PEM format")
|
clientPrefix = flag.String("client-prefix", "mqtt-benchmark", "MQTT client id prefix (suffixed with '-<client-num>'")
|
||||||
key = flag.String("key", "", "File path to your private key in PEM format")
|
clientCert = flag.String("client-cert", "", "Path to client certificate in PEM format")
|
||||||
|
clientKey = flag.String("client-key", "", "Path to private clientKey in PEM format")
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -83,17 +83,17 @@ func main() {
|
|||||||
log.Fatalf("Invalid arguments: messages count should be > 1, given: %v", *count)
|
log.Fatalf("Invalid arguments: messages count should be > 1, given: %v", *count)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *cert != "" && *key == "" {
|
if *clientCert != "" && *clientKey == "" {
|
||||||
log.Fatal("Invalid arguments: private key path missing")
|
log.Fatal("Invalid arguments: private clientKey path missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *cert == "" && *key != "" {
|
if *clientCert == "" && *clientKey != "" {
|
||||||
log.Fatalf("Invalid arguments: certificate path missing")
|
log.Fatalf("Invalid arguments: certificate path missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
var tlsConfig *tls.Config
|
var tlsConfig *tls.Config
|
||||||
if *cert != "" && *key != "" {
|
if *clientCert != "" && *clientKey != "" {
|
||||||
tlsConfig = generateTlsConfig(*cert, *key)
|
tlsConfig = generateTLSConfig(*clientCert, *clientKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
resCh := make(chan *RunResults)
|
resCh := make(chan *RunResults)
|
||||||
@@ -104,7 +104,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
c := &Client{
|
c := &Client{
|
||||||
ID: i,
|
ID: i,
|
||||||
ClientID: *clientID,
|
ClientID: *clientPrefix,
|
||||||
BrokerURL: *broker,
|
BrokerURL: *broker,
|
||||||
BrokerUser: *username,
|
BrokerUser: *username,
|
||||||
BrokerPass: *password,
|
BrokerPass: *password,
|
||||||
@@ -114,7 +114,7 @@ func main() {
|
|||||||
MsgQoS: byte(*qos),
|
MsgQoS: byte(*qos),
|
||||||
Quiet: *quiet,
|
Quiet: *quiet,
|
||||||
WaitTimeout: time.Duration(*wait) * time.Millisecond,
|
WaitTimeout: time.Duration(*wait) * time.Millisecond,
|
||||||
TlsConfig: tlsConfig,
|
TLSConfig: tlsConfig,
|
||||||
}
|
}
|
||||||
go c.Run(resCh)
|
go c.Run(resCh)
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ func printResults(results []*RunResults, totals *TotalResults, format string) {
|
|||||||
log.Fatalf("Error marshalling results: %v", err)
|
log.Fatalf("Error marshalling results: %v", err)
|
||||||
}
|
}
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
json.Indent(&out, data, "", "\t")
|
_ = json.Indent(&out, data, "", "\t")
|
||||||
|
|
||||||
fmt.Println(string(out.Bytes()))
|
fmt.Println(string(out.Bytes()))
|
||||||
default:
|
default:
|
||||||
@@ -211,7 +211,7 @@ func printResults(results []*RunResults, totals *TotalResults, format string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTlsConfig(certFile string, keyFile string) *tls.Config {
|
func generateTLSConfig(certFile string, keyFile string) *tls.Config {
|
||||||
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error reading certificate files: %v", err)
|
log.Fatalf("Error reading certificate files: %v", err)
|
||||||
|
Reference in New Issue
Block a user