forked from CodisLabs/codis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra_memleak.go
63 lines (56 loc) · 1.32 KB
/
extra_memleak.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
// Copyright 2016 CodisLabs. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package main
import (
"flag"
"fmt"
"time"
)
type ExtraMemleakTestCase struct {
proxy string
group int
nkeys int
}
func init() {
testcase = &ExtraMemleakTestCase{}
}
func (tc *ExtraMemleakTestCase) init() {
flag.StringVar(&tc.proxy, "proxy", "", "redis host:port")
flag.IntVar(&tc.group, "group", 8, "# of test players")
flag.IntVar(&tc.nkeys, "nkeys", 1000, "# of keys per test")
}
func (tc *ExtraMemleakTestCase) main() {
fmt.Println(`
!! PLEASE MAKE SURE !!
- compile : make MALLOC=libc -j4
- run : valgrind --leak-check=full
`)
tg := &TestGroup{}
tg.Reset()
var tags = NewZeroTags(10000)
for g := 0; g < tc.group; g++ {
tg.AddPlayer()
go tc.player(g, tg, tags)
}
tg.Start()
tg.Wait()
fmt.Println("done")
}
func (tc *ExtraMemleakTestCase) player(gid int, tg *TestGroup, tags *ZeroTags) {
tg.PlayerWait()
defer tg.PlayerDone()
c := NewConn(tc.proxy)
defer c.Close()
r := &Rand{time.Now().UnixNano()}
us := UnitSlice(make([]*Unit, tc.nkeys))
for i := 0; i < len(us); i++ {
key := fmt.Sprintf("extra_memleak_%d_%d_%d_tag{%s}", gid, i, r.Next(), tags.Get(i))
us[i] = NewUnit(key)
}
us.Del(c, false)
for _, u := range us {
u.Lpush(c, fmt.Sprintf("val_%d", r.Next()))
ops.Incr()
}
us.Del(c, false)
}