/
test_mget.go
89 lines (82 loc) · 1.73 KB
/
test_mget.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2015 Reborndb Org. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package main
import (
"flag"
"fmt"
"time"
)
type TestMgetTestCase struct {
proxy string
group int
round int
nkeys int
ntags int
}
func init() {
testcase = &TestMgetTestCase{}
}
func (tc *TestMgetTestCase) init() {
flag.StringVar(&tc.proxy, "proxy", "", "redis host:port")
flag.IntVar(&tc.group, "group", 8, "# of test players")
flag.IntVar(&tc.round, "round", 10000, "# of rounds per test player")
flag.IntVar(&tc.nkeys, "nkeys", 10000, "# of keys per test")
flag.IntVar(&tc.ntags, "ntags", 1000, "# of tags")
}
func (tc *TestMgetTestCase) main() {
go func() {
c := NewConn(tc.proxy)
for {
time.Sleep(time.Second * 5)
c.Check()
}
}()
tg := &TestGroup{}
tg.Reset()
for g := 0; g < tc.group; g++ {
tg.AddPlayer()
go tc.player(g, tg)
}
tg.Start()
tg.Wait()
fmt.Println("done")
}
func (tc *TestMgetTestCase) player(gid int, tg *TestGroup) {
tg.PlayerWait()
defer tg.PlayerDone()
c := NewConn(tc.proxy)
defer c.Close()
us := UnitSlice(make([]*Unit, tc.nkeys))
for i := 0; i < len(us); i++ {
key := fmt.Sprintf("test_mget_%d_{%d}_%d", gid, i%tc.ntags, i)
us[i] = NewUnit(key)
}
for _, u := range us {
u.Del(c, false)
ops.Incr()
}
for k := 0; k < tc.round; k++ {
for _, u := range us {
u.Incr(c)
}
const step = 16
for i := 0; i < len(us); i++ {
r := &Rand{time.Now().UnixNano()}
for j := 0; j < step; j++ {
u := us[uint(r.Next())%uint(len(us))]
u.Incr(c)
}
t := make([]*Unit, step)
for j := 0; j < step; j++ {
u := us[uint(r.Next())%uint(len(us))]
t[j] = u
}
UnitSlice(t).Mget(c)
ops.Incr()
}
}
for _, u := range us {
u.Del(c, false)
ops.Incr()
}
}