Bugfix #3: empty JSON output if '-clients=1' or '-count=1' (NaN sample std for a single sample)

This commit is contained in:
Alexandr Krylovskiy
2019-10-13 17:39:48 +02:00
parent 774ac6e90a
commit 8fb006ba61
2 changed files with 22 additions and 8 deletions

View File

@@ -55,9 +55,12 @@ func (c *Client) Run(res chan *RunResults) {
runResults.MsgTimeMin = stats.StatsMin(times)
runResults.MsgTimeMax = stats.StatsMax(times)
runResults.MsgTimeMean = stats.StatsMean(times)
runResults.MsgTimeStd = stats.StatsSampleStandardDeviation(times)
runResults.RunTime = duration.Seconds()
runResults.MsgsPerSec = float64(runResults.Successes) / duration.Seconds()
// calculate std if sample is > 1, otherwise leave as 0 (convention)
if c.MsgCount > 1 {
runResults.MsgTimeStd = stats.StatsSampleStandardDeviation(times)
}
// report results and exit
res <- runResults
@@ -123,8 +126,8 @@ func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool)
SetAutoReconnect(true).
SetOnConnectHandler(onConnected).
SetConnectionLostHandler(func(client mqtt.Client, reason error) {
log.Printf("CLIENT %v lost connection to the broker: %v. Will reconnect...\n", c.ID, reason.Error())
})
log.Printf("CLIENT %v lost connection to the broker: %v. Will reconnect...\n", c.ID, reason.Error())
})
if c.BrokerUser != "" && c.BrokerPass != "" {
opts.SetUsername(c.BrokerUser)
opts.SetPassword(c.BrokerPass)