redisLoadTest/testHandler.go

62 lines
1.4 KiB
Go
Raw Permalink Normal View History

2022-01-05 00:33:34 +00:00
package main
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
}
/**
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:
typedTimeValue := int64(1) * timeValue.Microseconds()
timesSlice = append(timesSlice, typedTimeValue)
2022-01-05 00:33:34 +00:00
case <-errorChan:
errorRate += 1
2022-01-05 00:33:34 +00:00
case <-endChan:
if len(errorChan) == 0 && len(timesChan) == 0 {
end = true
}
}
}
totalTimeChan <- timesSlice
totalErrorChan <- errorRate
2022-01-05 00:33:34 +00:00
}