redisLoadTest/burstTest.go
mitch 6c6595b2a0 Added output from tests
Tested tests and fixed errors
Adjusted default values
2022-01-05 01:09:52 -05:00

67 lines
1.9 KiB
Go

package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
"math"
"math/rand"
"time"
)
/**
getBurstTest starts goroutines for getRedis at the burstRateLimit per second
@param rdbPtr connection is a pointer to the redis connection
@param rate int requests per second for the test
@param keyMaxValue int max value to query the database and expect a return
*/
func getBurstTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.Duration) {
durationChannel := make(chan bool, 1)
burstRateLimiter := time.Tick(time.Millisecond * 250)
timesChan := make(chan time.Duration)
errorChan := make(chan bool)
endChan := make(chan bool)
totalErrorChan := make(chan int)
totalTimeChan := make(chan []int64)
quaterRate := math.Abs(float64(rate) / 4)
go func() {
for i := 0; i < int(duration.Seconds()); i++ {
<-time.Tick(time.Second)
}
durationChannel <- true
}()
go keepTotal(timesChan, errorChan, endChan, totalTimeChan, totalErrorChan)
fmt.Println("Starting burst test at", quaterRate, "requests per 250 milliseconds...")
end := false
for {
if end {
break
}
select {
case <-durationChannel:
end = true
case <-burstRateLimiter:
for i := float64(0); i < quaterRate; i++ {
//this might need toggled
time.Sleep(time.Millisecond * 5)
key := rand.Intn(keyMaxValue)
go getRedis(rdbPtr, key, timesChan, errorChan)
}
}
}
endChan <- true
totalTimesFloat := <-totalTimeChan
totalErrors := <-totalErrorChan
errorRate := totalErrors / len(totalTimesFloat)
totalTimes := intToFloat(totalTimesFloat)
mean, stddev, perc99, perc95 := getResponseTimes(totalTimes)
fmt.Println("Burst test concluded...")
fmt.Println("Total Requests:", len(totalTimesFloat))
fmt.Println("Error Rate:", errorRate, "ms")
fmt.Println("Mean:", mean, "ms")
fmt.Println("Standard Deviation:", stddev, "ms")
fmt.Println("95 Percentile:", perc95, "ms")
fmt.Println("99 Percentile:", perc99, "ms")
}