Cleanup, tested dockerfile and makefile
This commit is contained in:
parent
444bd9144b
commit
ce1472df66
10
Dockerfile
10
Dockerfile
@ -1,5 +1,11 @@
|
|||||||
FROM golang:1.17.5-bullseye AS builder
|
FROM golang:1.17.5-bullseye AS builder
|
||||||
|
|
||||||
|
RUN mkdir /tmp/redisloadtest
|
||||||
|
|
||||||
|
WORKDIR /tmp/redisloadtest
|
||||||
|
|
||||||
COPY go.mod .
|
COPY go.mod .
|
||||||
|
COPY go.sum .
|
||||||
COPY redisLoadTest.go .
|
COPY redisLoadTest.go .
|
||||||
|
|
||||||
RUN set -ex \
|
RUN set -ex \
|
||||||
@ -17,11 +23,11 @@ RUN useradd ${USER} --home-dir ${HOME}
|
|||||||
WORKDIR /tmp
|
WORKDIR /tmp
|
||||||
|
|
||||||
# Copy the binary from the builder stage
|
# Copy the binary from the builder stage
|
||||||
COPY --from=builder ${FILENAME} ./
|
COPY --from=builder /tmp/redisloadtest/${FILENAME} ./
|
||||||
|
|
||||||
RUN mv /tmp/${FILENAME} ${FILEPATH} \
|
RUN mv /tmp/${FILENAME} ${FILEPATH} \
|
||||||
&& chown ${USER}:${USER} ${FILEPATH}${FILENAME} \
|
&& chown ${USER}:${USER} ${FILEPATH}${FILENAME} \
|
||||||
&& chmod 4555 ${FILENAME}${FILEPATH} \
|
&& chmod 4555 ${FILEPATH}${FILENAME} \
|
||||||
&& rm -rf -- /tmp/* \
|
&& rm -rf -- /tmp/* \
|
||||||
|
|
||||||
WORKDIR ${HOME}
|
WORKDIR ${HOME}
|
||||||
|
5
go.mod
5
go.mod
@ -2,7 +2,10 @@ module redis
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require github.com/gomodule/redigo v1.8.6
|
require (
|
||||||
|
github.com/gomodule/redigo v1.8.6
|
||||||
|
github.com/montanaflynn/stats v0.6.6
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gomodule/redigo v1.8.6 h1:h7kHSqUl2kxeaQtVslsfUCPJ1oz2pxcyzLy4zezIzPw=
|
github.com/gomodule/redigo v1.8.6 h1:h7kHSqUl2kxeaQtVslsfUCPJ1oz2pxcyzLy4zezIzPw=
|
||||||
github.com/gomodule/redigo v1.8.6/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
github.com/gomodule/redigo v1.8.6/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||||
|
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
|
||||||
|
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gomodule/redigo/redis"
|
"github.com/gomodule/redigo/redis"
|
||||||
|
"github.com/montanaflynn/stats"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ctx = context.Background()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
buildTestData iterates through a goroutine of setRedis to build test data into the redis db
|
buildTestData iterates through a goroutine of setRedis to build test data into the redis db
|
||||||
@param redisPtr connection to redis
|
@param redisPtr connection to redis
|
||||||
@ -38,16 +36,30 @@ Then starts goroutines for getRedis at that interval
|
|||||||
@param rate int requests per second for the test
|
@param rate int requests per second for the test
|
||||||
@param keyMaxValue int max value to query the database and expect a return
|
@param keyMaxValue int max value to query the database and expect a return
|
||||||
*/
|
*/
|
||||||
func getRateTest(rdbPtr *redis.Conn, rate int, keyMaxValue int) {
|
func getRateTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.Duration) {
|
||||||
|
var durationChannel chan bool
|
||||||
x := int(math.Abs(60 / float64(rate) * 1000))
|
x := int(math.Abs(60 / float64(rate) * 1000))
|
||||||
rateLimiter := time.Tick(time.Millisecond * time.Duration(x))
|
rateLimiter := time.Tick(time.Millisecond * time.Duration(x))
|
||||||
|
|
||||||
fmt.Println("Starting Test at", rateLimiter, "milliseconds per request...")
|
fmt.Println("Starting Test at", rateLimiter, "milliseconds per request...")
|
||||||
//todo add end to test
|
go func() {
|
||||||
|
for i := 0; i < int(duration); i++ {
|
||||||
|
<-time.Tick(time.Second)
|
||||||
|
}
|
||||||
|
durationChannel <- true
|
||||||
|
}()
|
||||||
|
end := false
|
||||||
for {
|
for {
|
||||||
<-rateLimiter
|
if end {
|
||||||
key := rand.Intn(keyMaxValue)
|
break
|
||||||
go getRedis(rdbPtr, key)
|
}
|
||||||
|
select {
|
||||||
|
case <-rateLimiter:
|
||||||
|
key := rand.Intn(keyMaxValue)
|
||||||
|
go getRedis(rdbPtr, key)
|
||||||
|
case <-durationChannel:
|
||||||
|
end = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("Rate test concluded...")
|
fmt.Println("Rate test concluded...")
|
||||||
}
|
}
|
||||||
@ -58,15 +70,29 @@ getBurstTest starts goroutines for getRedis at the burstRateLimit per second
|
|||||||
@param rate int requests per second for the test
|
@param rate int requests per second for the test
|
||||||
@param keyMaxValue int max value to query the database and expect a return
|
@param keyMaxValue int max value to query the database and expect a return
|
||||||
*/
|
*/
|
||||||
func getBurstTest(rdbPtr *redis.Conn, rate int, keyMaxValue int) {
|
func getBurstTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.Duration) {
|
||||||
|
var durationChannel chan bool
|
||||||
burstRateLimiter := time.Tick(time.Second)
|
burstRateLimiter := time.Tick(time.Second)
|
||||||
//todo add end to test
|
go func() {
|
||||||
|
for i := 0; i < int(duration); i++ {
|
||||||
|
<-time.Tick(time.Second)
|
||||||
|
}
|
||||||
|
durationChannel <- true
|
||||||
|
}()
|
||||||
fmt.Println("Starting burst test at", rate, "requests per second...")
|
fmt.Println("Starting burst test at", rate, "requests per second...")
|
||||||
|
end := false
|
||||||
for {
|
for {
|
||||||
<-burstRateLimiter
|
if end {
|
||||||
for i := 0; i < rate; i++ {
|
break
|
||||||
key := rand.Intn(keyMaxValue)
|
}
|
||||||
go getRedis(rdbPtr, key)
|
select {
|
||||||
|
case <-burstRateLimiter:
|
||||||
|
for i := 0; i < rate; i++ {
|
||||||
|
key := rand.Intn(keyMaxValue)
|
||||||
|
go getRedis(rdbPtr, key)
|
||||||
|
}
|
||||||
|
case <-durationChannel:
|
||||||
|
end = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("Burst test concluded...")
|
fmt.Println("Burst test concluded...")
|
||||||
@ -121,6 +147,22 @@ func newPool(host string) *redis.Pool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func keepTotal(timesSlice *[]float64, timesChan chan float64, endChan chan bool) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
hostPtr := flag.String("host", "", "Redis Server FQDN:port")
|
hostPtr := flag.String("host", "", "Redis Server FQDN:port")
|
||||||
//usernamePtr := flag.String("username", "", "Redis Server username")
|
//usernamePtr := flag.String("username", "", "Redis Server username")
|
||||||
@ -131,6 +173,7 @@ func main() {
|
|||||||
burstPtr := flag.Bool("burst", true, "Boolean burst test default true")
|
burstPtr := flag.Bool("burst", true, "Boolean burst test default true")
|
||||||
//todo this should be off that same csv rather than an input
|
//todo this should be off that same csv rather than an input
|
||||||
maxEntriesPtr := flag.Int("dbEntries", 50000, "Test rate limit, default 50/sec")
|
maxEntriesPtr := flag.Int("dbEntries", 50000, "Test rate limit, default 50/sec")
|
||||||
|
testDurationPtr := flag.Int("duration", 60, "Duration of each test")
|
||||||
|
|
||||||
host := *hostPtr
|
host := *hostPtr
|
||||||
//todo add username/password support
|
//todo add username/password support
|
||||||
@ -141,6 +184,8 @@ func main() {
|
|||||||
rate := *ratePtr
|
rate := *ratePtr
|
||||||
burst := *burstPtr
|
burst := *burstPtr
|
||||||
keyMaxValue := *maxEntriesPtr
|
keyMaxValue := *maxEntriesPtr
|
||||||
|
durationInt := *testDurationPtr
|
||||||
|
duration := time.Duration(time.Second * time.Duration(durationInt))
|
||||||
|
|
||||||
pool := newPool(host)
|
pool := newPool(host)
|
||||||
client := pool.Get()
|
client := pool.Get()
|
||||||
@ -149,9 +194,9 @@ func main() {
|
|||||||
if initializeDB {
|
if initializeDB {
|
||||||
buildTestData(&client, 50000)
|
buildTestData(&client, 50000)
|
||||||
}
|
}
|
||||||
getRateTest(&client, rate, keyMaxValue)
|
getRateTest(&client, rate, keyMaxValue, duration)
|
||||||
if burst {
|
if burst {
|
||||||
getBurstTest(&client, rate, keyMaxValue)
|
getBurstTest(&client, rate, keyMaxValue, duration)
|
||||||
}
|
}
|
||||||
fmt.Println("Tests completed...")
|
fmt.Println("Tests completed...")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user