-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress.go
44 lines (40 loc) · 1.28 KB
/
stress.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
package main
import (
"fmt"
"time"
redigocluster "github.com/chasex/redis-go-cluster"
redigo "github.com/garyburd/redigo/redis"
)
// StressCluster is a simple function to stress test a redis cluster
func StressCluster(hosts []string, minMsgSize, maxMsgSize, numOfMsg int) error {
c, err := redigocluster.NewCluster(&redigocluster.Options{
StartNodes: hosts,
ConnTimeout: 50 * time.Millisecond,
ReadTimeout: 50 * time.Millisecond,
WriteTimeout: 50 * time.Millisecond,
KeepAlive: 16,
AliveTime: 60 * time.Second,
})
if err != nil {
return err
}
fmt.Println("=====STRINGS=====")
printResult(ClusterStressString(*c, minMsgSize, maxMsgSize, numOfMsg), numOfMsg)
fmt.Println("=====BYTES=====")
printResult(ClusterStressBytes(*c, minMsgSize, maxMsgSize, numOfMsg), numOfMsg)
return nil
}
// StressNode is fuction that executes a series of stress tests in a sigle node
// of redis
func StressNode(host string, minMsgSize, maxMsgSize, numOfMsg int) error {
c, err := redigo.Dial("tcp", host)
if err != nil {
return err
}
defer c.Close()
fmt.Println("=====STRINGS=====")
printResult(NodeStressString(c, numOfMsg, minMsgSize, maxMsgSize), numOfMsg)
fmt.Println("=====BYTES=====")
printResult(NodeStressBytes(c, numOfMsg, minMsgSize, maxMsgSize), numOfMsg)
return nil
}