Added quiet flag.

This commit is contained in:
enobufs
2017-04-14 19:10:01 -07:00
parent 00e1491031
commit 76be7d1cff
3 changed files with 18 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ Usage of mqtt-benchmark:
-format="text": Output format: text|json
-password="": MQTT password (empty if auth disabled)
-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)
-topic="/test": MQTT topic for incoming message
-username="": MQTT username (empty if auth disabled)
@@ -57,7 +58,7 @@ Total Bandwidth (msg/sec): 676.112
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: [
...

View File

@@ -20,6 +20,7 @@ type Client struct {
MsgSize int
MsgCount int
MsgQoS byte
Quiet bool
}
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) {
onConnected := func(client mqtt.Client) {
log.Printf("CLIENT %v is connected to the broker %v\n", c.ID, c.BrokerURL)
if !c.Quiet {
log.Printf("CLIENT %v is connected to the broker %v\n", c.ID, c.BrokerURL)
}
ctr := 0
for {
select {
@@ -98,12 +101,16 @@ func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool)
out <- m
if ctr > 0 && ctr%100 == 0 {
log.Printf("CLIENT %v published %v messages and keeps publishing...\n", c.ID, ctr)
if !c.Quiet {
log.Printf("CLIENT %v published %v messages and keeps publishing...\n", c.ID, ctr)
}
}
ctr++
case <-doneGen:
donePub <- true
log.Printf("CLIENT %v is done publishing\n", c.ID)
if !c.Quiet {
log.Printf("CLIENT %v is done publishing\n", c.ID)
}
return
}
}

View File

@@ -67,6 +67,7 @@ func main() {
count = flag.Int("count", 100, "Number of messages to send per client")
clients = flag.Int("clients", 10, "Number of clients to start")
format = flag.String("format", "text", "Output format: text|json")
quiet = flag.Bool("quiet", false, "Suppress logs while running")
)
flag.Parse()
@@ -77,7 +78,9 @@ func main() {
resCh := make(chan *RunResults)
start := time.Now()
for i := 0; i < *clients; i++ {
log.Println("Starting client ", i)
if !*quiet {
log.Println("Starting client ", i)
}
c := &Client{
ID: i,
BrokerURL: *broker,
@@ -87,6 +90,7 @@ func main() {
MsgSize: *size,
MsgCount: *count,
MsgQoS: byte(*qos),
Quiet: *quiet,
}
go c.Run(resCh)
}