mirror of
https://github.com/wwhai/mqtt-benchmark.git
synced 2025-10-07 08:30:56 +08:00
Bugfix #3: empty JSON output if '-clients=1' or '-count=1' (NaN sample std for a single sample)
This commit is contained in:
21
main.go
21
main.go
@@ -72,7 +72,11 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
if *clients < 1 {
|
||||
log.Fatal("Invlalid arguments")
|
||||
log.Fatalf("Invalid arguments: number of clients should be > 1, given: %v", *clients)
|
||||
}
|
||||
|
||||
if *count < 1 {
|
||||
log.Fatalf("Invalid arguments: messages count should be > 1, given: %v", *count)
|
||||
}
|
||||
|
||||
resCh := make(chan *RunResults)
|
||||
@@ -101,12 +105,13 @@ func main() {
|
||||
results[i] = <-resCh
|
||||
}
|
||||
totalTime := time.Now().Sub(start)
|
||||
totals := calculateTotalResults(results, totalTime)
|
||||
totals := calculateTotalResults(results, totalTime, *clients)
|
||||
|
||||
// print stats
|
||||
printResults(results, totals, *format)
|
||||
}
|
||||
func calculateTotalResults(results []*RunResults, totalTime time.Duration) *TotalResults {
|
||||
|
||||
func calculateTotalResults(results []*RunResults, totalTime time.Duration, sampleSize int) *TotalResults {
|
||||
totals := new(TotalResults)
|
||||
totals.TotalRunTime = totalTime.Seconds()
|
||||
|
||||
@@ -138,7 +143,10 @@ func calculateTotalResults(results []*RunResults, totalTime time.Duration) *Tota
|
||||
totals.AvgMsgsPerSec = stats.StatsMean(msgsPerSecs)
|
||||
totals.AvgRunTime = stats.StatsMean(runTimes)
|
||||
totals.MsgTimeMeanAvg = stats.StatsMean(msgTimeMeans)
|
||||
totals.MsgTimeMeanStd = stats.StatsSampleStandardDeviation(msgTimeMeans)
|
||||
// calculate std if sample is > 1, otherwise leave as 0 (convention)
|
||||
if sampleSize > 1 {
|
||||
totals.MsgTimeMeanStd = stats.StatsSampleStandardDeviation(msgTimeMeans)
|
||||
}
|
||||
|
||||
return totals
|
||||
}
|
||||
@@ -150,7 +158,10 @@ func printResults(results []*RunResults, totals *TotalResults, format string) {
|
||||
Runs: results,
|
||||
Totals: totals,
|
||||
}
|
||||
data, _ := json.Marshal(jr)
|
||||
data, err := json.Marshal(jr)
|
||||
if err != nil {
|
||||
log.Fatalf("Error marshalling results: %v", err)
|
||||
}
|
||||
var out bytes.Buffer
|
||||
json.Indent(&out, data, "", "\t")
|
||||
|
||||
|
Reference in New Issue
Block a user