-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadtest.go
51 lines (38 loc) · 1.08 KB
/
loadtest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func generatePerpetualTraffic(nodeList []*Node, key string) {
for {
time.Sleep(time.Millisecond * 1)
id := rand.Intn(len(nodeList))
nodeList[id].Inc(key, id)
}
}
func Loadtest() {
// wtf to test ?
// 1000 nodes
printInfo := false // few print outs
nodeCount := 1000 // cluster node size
queryKey := "abc"
chatterSize := 10 // speaks with atmost 5 random nodes
maxProcessFrequency := 5 // a node will process this query atmost 5 times
statusCheckFrequencyInMilliSeconds := 5 // will print status every 10 ms
tracker := NewTracker()
nodeList := []*Node{}
for i := 0; i < nodeCount; i++ {
nd := NewNode(fmt.Sprint("node-", i), printInfo)
tracker.AddNode(nd)
nodeList = append(nodeList, nd)
}
wg := &sync.WaitGroup{}
wg.Add(1)
go generatePerpetualTraffic(nodeList, queryKey)
time.Sleep(time.Second * 2)
query := NewQuery(queryKey, chatterSize, maxProcessFrequency, statusCheckFrequencyInMilliSeconds, printInfo)
nodeList[nodeCount/2-1].Query(query)
wg.Wait()
}