mirror of
https://github.com/wwhai/mqtt-benchmark.git
synced 2025-10-05 07:37:03 +08:00
Fixed formatting and linter errors
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
mqtt-benchmark
|
||||||
|
@@ -6,7 +6,7 @@ A simple MQTT (broker) benchmarking tool.
|
|||||||
Installation:
|
Installation:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go get github.com/krylovsk/mqtt-benchmark
|
go install 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:
|
||||||
|
27
client.go
27
client.go
@@ -19,7 +19,7 @@ type Client struct {
|
|||||||
BrokerUser string
|
BrokerUser string
|
||||||
BrokerPass string
|
BrokerPass string
|
||||||
MsgTopic string
|
MsgTopic string
|
||||||
MsgPayload string
|
MsgPayload string
|
||||||
MsgSize int
|
MsgSize int
|
||||||
MsgCount int
|
MsgCount int
|
||||||
MsgQoS byte
|
MsgQoS byte
|
||||||
@@ -57,7 +57,7 @@ func (c *Client) Run(res chan *RunResults) {
|
|||||||
}
|
}
|
||||||
case <-donePub:
|
case <-donePub:
|
||||||
// calculate results
|
// calculate results
|
||||||
duration := time.Now().Sub(started)
|
duration := time.Since(started)
|
||||||
runResults.MsgTimeMin = stats.StatsMin(times)
|
runResults.MsgTimeMin = stats.StatsMin(times)
|
||||||
runResults.MsgTimeMax = stats.StatsMax(times)
|
runResults.MsgTimeMax = stats.StatsMax(times)
|
||||||
runResults.MsgTimeMean = stats.StatsMean(times)
|
runResults.MsgTimeMean = stats.StatsMean(times)
|
||||||
@@ -77,22 +77,21 @@ func (c *Client) Run(res chan *RunResults) {
|
|||||||
|
|
||||||
func (c *Client) genMessages(ch chan *Message, done chan bool) {
|
func (c *Client) genMessages(ch chan *Message, done chan bool) {
|
||||||
var payload interface{}
|
var payload interface{}
|
||||||
// set payload if specified
|
// set payload if specified
|
||||||
if c.MsgPayload != "" {
|
if c.MsgPayload != "" {
|
||||||
payload = c.MsgPayload
|
payload = c.MsgPayload
|
||||||
} else {
|
} else {
|
||||||
payload = make([]byte, c.MsgSize)
|
payload = make([]byte, c.MsgSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- &Message{
|
ch <- &Message{
|
||||||
Topic: c.MsgTopic,
|
Topic: c.MsgTopic,
|
||||||
QoS: c.MsgQoS,
|
QoS: c.MsgQoS,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
done <- true
|
done <- true
|
||||||
// log.Printf("CLIENT %v is done generating messages\n", c.ID)
|
// log.Printf("CLIENT %v is done generating messages\n", c.ID)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool) {
|
func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool) {
|
||||||
|
9
main.go
9
main.go
@@ -60,7 +60,7 @@ 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")
|
||||||
payload = flag.String("payload", "", "MQTT message payload. If empty, then payload is generated based on the size parameter")
|
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)")
|
username = flag.String("username", "", "MQTT client username (empty if auth disabled)")
|
||||||
password = flag.String("password", "", "MQTT client password (empty if auth disabled)")
|
password = flag.String("password", "", "MQTT client password (empty if auth disabled)")
|
||||||
qos = flag.Int("qos", 1, "QoS for published messages")
|
qos = flag.Int("qos", 1, "QoS for published messages")
|
||||||
@@ -110,7 +110,7 @@ func main() {
|
|||||||
BrokerUser: *username,
|
BrokerUser: *username,
|
||||||
BrokerPass: *password,
|
BrokerPass: *password,
|
||||||
MsgTopic: *topic,
|
MsgTopic: *topic,
|
||||||
MsgPayload: *payload,
|
MsgPayload: *payload,
|
||||||
MsgSize: *size,
|
MsgSize: *size,
|
||||||
MsgCount: *count,
|
MsgCount: *count,
|
||||||
MsgQoS: byte(*qos),
|
MsgQoS: byte(*qos),
|
||||||
@@ -126,7 +126,7 @@ func main() {
|
|||||||
for i := 0; i < *clients; i++ {
|
for i := 0; i < *clients; i++ {
|
||||||
results[i] = <-resCh
|
results[i] = <-resCh
|
||||||
}
|
}
|
||||||
totalTime := time.Now().Sub(start)
|
totalTime := time.Since(start)
|
||||||
totals := calculateTotalResults(results, totalTime, *clients)
|
totals := calculateTotalResults(results, totalTime, *clients)
|
||||||
|
|
||||||
// print stats
|
// print stats
|
||||||
@@ -187,7 +187,7 @@ func printResults(results []*RunResults, totals *TotalResults, format string) {
|
|||||||
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(out.String())
|
||||||
default:
|
default:
|
||||||
for _, res := range results {
|
for _, res := range results {
|
||||||
fmt.Printf("======= CLIENT %d =======\n", res.ID)
|
fmt.Printf("======= CLIENT %d =======\n", res.ID)
|
||||||
@@ -210,7 +210,6 @@ func printResults(results []*RunResults, totals *TotalResults, format string) {
|
|||||||
fmt.Printf("Average Bandwidth (msg/sec): %.3f\n", totals.AvgMsgsPerSec)
|
fmt.Printf("Average Bandwidth (msg/sec): %.3f\n", totals.AvgMsgsPerSec)
|
||||||
fmt.Printf("Total Bandwidth (msg/sec): %.3f\n", totals.TotalMsgsPerSec)
|
fmt.Printf("Total Bandwidth (msg/sec): %.3f\n", totals.TotalMsgsPerSec)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTLSConfig(certFile string, keyFile string) *tls.Config {
|
func generateTLSConfig(certFile string, keyFile string) *tls.Config {
|
||||||
|
Reference in New Issue
Block a user