Unfinished changes
This commit is contained in:
parent
77a1ab2e8c
commit
e39129618b
5
LICENSE.md
Normal file
5
LICENSE.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
"THE BEER-WARE LICENSE" (Revision 42)
|
||||||
|
|
||||||
|
<mitch@nerdfortress.dev> wrote this file. As long as you retain this notice you
|
||||||
|
can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
|
this stuff is worth it, you can buy me a beer in return
|
@ -1,5 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||||
|
* <mitch@nerdfortress.dev> wrote this file. As long as you retain this notice you
|
||||||
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
|
* this stuff is worth it, you can buy me a beer in return
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -19,13 +28,13 @@ buildTestData iterates through a goroutine of setRedis to build test data into t
|
|||||||
func buildTestData(rdbPtr *redis.Conn, size int) {
|
func buildTestData(rdbPtr *redis.Conn, size int) {
|
||||||
fmt.Println("Initializing Test Data...")
|
fmt.Println("Initializing Test Data...")
|
||||||
var waitGroup sync.WaitGroup
|
var waitGroup sync.WaitGroup
|
||||||
for i := 0; i < size; i++ {
|
for i := 1; i < 50000; i++ {
|
||||||
key := i
|
key := i
|
||||||
value := "ThisIsATestStringThatShouldBeReplacedWithSomethingMoreRandomMaybeFromAnInputOrCSV"
|
value := "ThisIsATestStringThatShouldBeReplacedWithSomethingMoreRandomMaybeFromAnInputOrCSV"
|
||||||
go setRedis(rdbPtr, key, value, &waitGroup)
|
setRedis(rdbPtr, key, value, &waitGroup)
|
||||||
waitGroup.Add(1)
|
//waitGroup.Add(1)
|
||||||
}
|
}
|
||||||
waitGroup.Wait()
|
//waitGroup.Wait()
|
||||||
fmt.Println("Database Initialized...")
|
fmt.Println("Database Initialized...")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,13 +46,15 @@ Then starts goroutines for getRedis at that interval
|
|||||||
@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, duration time.Duration) {
|
func getRateTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.Duration) {
|
||||||
var durationChannel chan bool
|
durationChannel := make(chan bool, 1)
|
||||||
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...")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < int(duration); i++ {
|
for i := 0; i < int(duration.Seconds()); i++ {
|
||||||
|
fmt.Println(i, int(duration.Seconds()))
|
||||||
<-time.Tick(time.Second)
|
<-time.Tick(time.Second)
|
||||||
}
|
}
|
||||||
durationChannel <- true
|
durationChannel <- true
|
||||||
@ -54,11 +65,13 @@ func getRateTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.Du
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
case <-durationChannel:
|
||||||
|
fmt.Println("Closing Test...")
|
||||||
|
end = true
|
||||||
case <-rateLimiter:
|
case <-rateLimiter:
|
||||||
key := rand.Intn(keyMaxValue)
|
key := rand.Intn(keyMaxValue)
|
||||||
|
fmt.Println(key)
|
||||||
go getRedis(rdbPtr, key)
|
go getRedis(rdbPtr, key)
|
||||||
case <-durationChannel:
|
|
||||||
end = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("Rate test concluded...")
|
fmt.Println("Rate test concluded...")
|
||||||
@ -71,10 +84,10 @@ getBurstTest starts goroutines for getRedis at the burstRateLimit per second
|
|||||||
@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, duration time.Duration) {
|
func getBurstTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.Duration) {
|
||||||
var durationChannel chan bool
|
durationChannel := make(chan bool, 1)
|
||||||
burstRateLimiter := time.Tick(time.Second)
|
burstRateLimiter := time.Tick(time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < int(duration); i++ {
|
for i := 0; i < int(duration.Seconds()); i++ {
|
||||||
<-time.Tick(time.Second)
|
<-time.Tick(time.Second)
|
||||||
}
|
}
|
||||||
durationChannel <- true
|
durationChannel <- true
|
||||||
@ -86,13 +99,13 @@ func getBurstTest(rdbPtr *redis.Conn, rate int, keyMaxValue int, duration time.D
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
case <-durationChannel:
|
||||||
|
end = true
|
||||||
case <-burstRateLimiter:
|
case <-burstRateLimiter:
|
||||||
for i := 0; i < rate; i++ {
|
for i := 0; i < rate; i++ {
|
||||||
key := rand.Intn(keyMaxValue)
|
key := rand.Intn(keyMaxValue)
|
||||||
go getRedis(rdbPtr, key)
|
go getRedis(rdbPtr, key)
|
||||||
}
|
}
|
||||||
case <-durationChannel:
|
|
||||||
end = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("Burst test concluded...")
|
fmt.Println("Burst test concluded...")
|
||||||
@ -106,12 +119,12 @@ setRateTest sets key/value into database
|
|||||||
*/
|
*/
|
||||||
func setRedis(rdbPtr *redis.Conn, key int, value string, waitGroup *sync.WaitGroup) {
|
func setRedis(rdbPtr *redis.Conn, key int, value string, waitGroup *sync.WaitGroup) {
|
||||||
rdb := *rdbPtr
|
rdb := *rdbPtr
|
||||||
|
//defer waitGroup.Done()
|
||||||
_, err := rdb.Do("Set", key, value)
|
_, err := rdb.Do("Set", key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer waitGroup.Done()
|
fmt.Println(err, key, value)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer waitGroup.Done()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,7 +160,20 @@ func newPool(host string) *redis.Pool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func keepTotal(timesSlice *[]float64, timesChan chan float64, endChan chan bool) {
|
func keepTotal(timesChan chan float64, errorChan chan bool, endChan chan bool) ([]float64, int) {
|
||||||
|
var timesSlice []float64
|
||||||
|
var errorRate int
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-endChan:
|
||||||
|
break
|
||||||
|
case timeValue := <-timesChan:
|
||||||
|
timesSlice = append(timesSlice, timeValue)
|
||||||
|
case <-errorChan:
|
||||||
|
errorRate++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return timesSlice, errorRate
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +199,9 @@ 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")
|
testDurationPtr := flag.Int("duration", 10, "Duration of each test")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
host := *hostPtr
|
host := *hostPtr
|
||||||
//todo add username/password support
|
//todo add username/password support
|
||||||
//username := *usernamePtr
|
//username := *usernamePtr
|
||||||
@ -191,7 +218,7 @@ func main() {
|
|||||||
client := pool.Get()
|
client := pool.Get()
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
if initializeDB {
|
if !initializeDB {
|
||||||
buildTestData(&client, 50000)
|
buildTestData(&client, 50000)
|
||||||
}
|
}
|
||||||
getRateTest(&client, rate, keyMaxValue, duration)
|
getRateTest(&client, rate, keyMaxValue, duration)
|
||||||
|
Loading…
Reference in New Issue
Block a user