mirror of
https://github.com/wwhai/mqtt-benchmark.git
synced 2025-10-05 07:37:03 +08:00
Added quiet flag.
This commit is contained in:
@@ -20,6 +20,7 @@ Usage of mqtt-benchmark:
|
|||||||
-format="text": Output format: text|json
|
-format="text": Output format: text|json
|
||||||
-password="": MQTT password (empty if auth disabled)
|
-password="": MQTT password (empty if auth disabled)
|
||||||
-qos=1: QoS for published messages
|
-qos=1: QoS for published messages
|
||||||
|
-quiet=false : Suppress logs while running (except errors and the result)
|
||||||
-size=100: Size of the messages payload (bytes)
|
-size=100: Size of the messages payload (bytes)
|
||||||
-topic="/test": MQTT topic for incoming message
|
-topic="/test": MQTT topic for incoming message
|
||||||
-username="": MQTT username (empty if auth disabled)
|
-username="": MQTT username (empty if auth disabled)
|
||||||
@@ -57,7 +58,7 @@ Total Bandwidth (msg/sec): 676.112
|
|||||||
Similarly, in JSON:
|
Similarly, in JSON:
|
||||||
|
|
||||||
```
|
```
|
||||||
> mqtt-benchmark --broker tcp://broker.local:1883 --count 100 --size 100 --clients 100 --qos 2 --format json
|
> mqtt-benchmark --broker tcp://broker.local:1883 --count 100 --size 100 --clients 100 --qos 2 --format json --quiet
|
||||||
{
|
{
|
||||||
runs: [
|
runs: [
|
||||||
...
|
...
|
||||||
|
@@ -20,6 +20,7 @@ type Client struct {
|
|||||||
MsgSize int
|
MsgSize int
|
||||||
MsgCount int
|
MsgCount int
|
||||||
MsgQoS byte
|
MsgQoS byte
|
||||||
|
Quiet bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Run(res chan *RunResults) {
|
func (c *Client) Run(res chan *RunResults) {
|
||||||
@@ -80,7 +81,9 @@ func (c *Client) genMessages(ch chan *Message, done chan bool) {
|
|||||||
|
|
||||||
func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool) {
|
func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool) {
|
||||||
onConnected := func(client mqtt.Client) {
|
onConnected := func(client mqtt.Client) {
|
||||||
|
if !c.Quiet {
|
||||||
log.Printf("CLIENT %v is connected to the broker %v\n", c.ID, c.BrokerURL)
|
log.Printf("CLIENT %v is connected to the broker %v\n", c.ID, c.BrokerURL)
|
||||||
|
}
|
||||||
ctr := 0
|
ctr := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -98,12 +101,16 @@ func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool)
|
|||||||
out <- m
|
out <- m
|
||||||
|
|
||||||
if ctr > 0 && ctr%100 == 0 {
|
if ctr > 0 && ctr%100 == 0 {
|
||||||
|
if !c.Quiet {
|
||||||
log.Printf("CLIENT %v published %v messages and keeps publishing...\n", c.ID, ctr)
|
log.Printf("CLIENT %v published %v messages and keeps publishing...\n", c.ID, ctr)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctr++
|
ctr++
|
||||||
case <-doneGen:
|
case <-doneGen:
|
||||||
donePub <- true
|
donePub <- true
|
||||||
|
if !c.Quiet {
|
||||||
log.Printf("CLIENT %v is done publishing\n", c.ID)
|
log.Printf("CLIENT %v is done publishing\n", c.ID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@@ -67,6 +67,7 @@ func main() {
|
|||||||
count = flag.Int("count", 100, "Number of messages to send per client")
|
count = flag.Int("count", 100, "Number of messages to send per client")
|
||||||
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")
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -77,7 +78,9 @@ func main() {
|
|||||||
resCh := make(chan *RunResults)
|
resCh := make(chan *RunResults)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
for i := 0; i < *clients; i++ {
|
for i := 0; i < *clients; i++ {
|
||||||
|
if !*quiet {
|
||||||
log.Println("Starting client ", i)
|
log.Println("Starting client ", i)
|
||||||
|
}
|
||||||
c := &Client{
|
c := &Client{
|
||||||
ID: i,
|
ID: i,
|
||||||
BrokerURL: *broker,
|
BrokerURL: *broker,
|
||||||
@@ -87,6 +90,7 @@ func main() {
|
|||||||
MsgSize: *size,
|
MsgSize: *size,
|
||||||
MsgCount: *count,
|
MsgCount: *count,
|
||||||
MsgQoS: byte(*qos),
|
MsgQoS: byte(*qos),
|
||||||
|
Quiet: *quiet,
|
||||||
}
|
}
|
||||||
go c.Run(resCh)
|
go c.Run(resCh)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user