2022-01-05 00:33:34 +00:00
|
|
|
package main
|
|
|
|
|
2022-01-05 06:09:52 +00:00
|
|
|
import (
|
|
|
|
"github.com/montanaflynn/stats"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
intToFloat takes []int64 and converts it to []float64 for processing
|
|
|
|
*/
|
|
|
|
func intToFloat(times []int64) []float64 {
|
|
|
|
var floatArray []float64
|
|
|
|
for timeRange := range times {
|
|
|
|
floatArray = append(floatArray, float64(timeRange))
|
|
|
|
}
|
|
|
|
return floatArray
|
|
|
|
}
|
2022-01-05 00:33:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
getResponseTimes takes a list of ints and returns mean, stddev, 95p, 99p
|
|
|
|
Uses stats library to calculate mean, stddev, 95p, 99p
|
|
|
|
*/
|
|
|
|
func getResponseTimes(times []float64) (float64, float64, float64, float64) {
|
|
|
|
mean, _ := stats.Mean(times)
|
|
|
|
stddev, _ := stats.StandardDeviation(times)
|
|
|
|
perc99, _ := stats.Percentile(times, 99.00)
|
|
|
|
perc95, _ := stats.Percentile(times, 95.00)
|
|
|
|
return mean, stddev, perc99, perc95
|
|
|
|
}
|
|
|
|
|
2022-01-05 06:09:52 +00:00
|
|
|
/**
|
|
|
|
keepTotal takes several channels and keeps a running total of
|
|
|
|
duration and errors
|
|
|
|
*/
|
|
|
|
func keepTotal(timesChan chan time.Duration,
|
|
|
|
errorChan chan bool,
|
|
|
|
endChan chan bool,
|
|
|
|
totalTimeChan chan []int64,
|
|
|
|
totalErrorChan chan int) {
|
|
|
|
var timesSlice []int64
|
2022-01-05 00:33:34 +00:00
|
|
|
var errorRate int
|
|
|
|
end := false
|
|
|
|
for {
|
|
|
|
if end {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case timeValue := <-timesChan:
|
2022-01-05 06:09:52 +00:00
|
|
|
typedTimeValue := int64(1) * timeValue.Microseconds()
|
|
|
|
timesSlice = append(timesSlice, typedTimeValue)
|
2022-01-05 00:33:34 +00:00
|
|
|
case <-errorChan:
|
2022-01-05 06:09:52 +00:00
|
|
|
errorRate += 1
|
2022-01-05 00:33:34 +00:00
|
|
|
case <-endChan:
|
|
|
|
if len(errorChan) == 0 && len(timesChan) == 0 {
|
|
|
|
end = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-05 06:09:52 +00:00
|
|
|
totalTimeChan <- timesSlice
|
|
|
|
totalErrorChan <- errorRate
|
2022-01-05 00:33:34 +00:00
|
|
|
}
|