-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_test.go
111 lines (107 loc) · 3.29 KB
/
client_test.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package rueidis_benchmark
import (
"context"
"flag"
"testing"
"time"
"github.com/redis/go-redis/v9"
"github.com/redis/rueidis"
)
var lib = flag.String("lib", "", "lib to benchmark")
func Benchmark(b *testing.B) {
bench := func(b *testing.B, address []string, parallelisms []int) {
var (
ctx = context.Background()
keySizes = []int{16}
valSizes = []int{64, 256, 1024}
builders = []TargetBuilder{
{
Name: "Set",
Make: func(bench Bench) (Target, error) {
switch *lib {
case "goredis":
client := redis.NewUniversalClient(&redis.UniversalOptions{Addrs: address})
if err := client.FlushAll(ctx).Err(); err != nil {
return Target{}, err
}
return Target{
Close: func() { client.Close() },
Do: func(key string, value string) error {
return client.Set(ctx, key, value, 0).Err()
},
}, nil
default:
client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: address, PipelineMultiplex: -1})
if err != nil {
return Target{}, err
}
if err := client.Do(ctx, client.B().Flushall().Build()).Error(); err != nil {
return Target{}, err
}
return Target{
Close: func() { client.Close() },
Do: func(key string, value string) error {
return client.Do(ctx, client.B().Set().Key(key).Value(value).Build()).Error()
},
}, nil
}
},
},
{
Name: "Get",
Make: func(bench Bench) (Target, error) {
switch *lib {
case "goredis":
client := redis.NewUniversalClient(&redis.UniversalOptions{Addrs: address})
if err := client.FlushAll(ctx).Err(); err != nil {
return Target{}, err
}
if err := client.Set(ctx, bench.Key, bench.Val, 0).Err(); err != nil {
return Target{}, err
}
return Target{
Close: func() { client.Close() },
Do: func(key string, value string) error {
return client.Get(ctx, key).Err()
},
}, nil
default:
client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: address, PipelineMultiplex: -1})
if err != nil {
return Target{}, err
}
if err := client.Do(ctx, client.B().Flushall().Build()).Error(); err != nil {
return Target{}, err
}
if err := client.Do(ctx, client.B().Set().Key(bench.Key).Value(bench.Val).Build()).Error(); err != nil {
return Target{}, err
}
if *lib == "rueicsc" {
return Target{
Close: func() { client.Close() },
Do: func(key string, value string) error {
return client.DoCache(ctx, client.B().Get().Key(key).Cache(), 10*time.Second).Error()
},
}, nil
} else {
return Target{
Close: func() { client.Close() },
Do: func(key string, value string) error {
return client.Do(ctx, client.B().Get().Key(key).Build()).Error()
},
}, nil
}
}
},
},
}
)
RunBenchmark(b, compose(parallelisms, keySizes, valSizes, builders))
}
b.Run("OneNode", func(b *testing.B) {
bench(b, []string{"127.0.0.1:6379"}, []int{1, 8, 64})
})
b.Run("Cluster", func(b *testing.B) {
bench(b, []string{"127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"}, []int{1, 8, 64})
})
}