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 -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: [
... ...

View File

@@ -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) {
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 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 {
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++ ctr++
case <-doneGen: case <-doneGen:
donePub <- true 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 return
} }
} }

View File

@@ -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++ {
log.Println("Starting client ", i) if !*quiet {
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)
} }