-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_command.go
222 lines (199 loc) · 5.68 KB
/
test_command.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package main
import (
"fmt"
"strings"
"github.com/google/gops/agent"
"github.com/urfave/cli/v2"
"github.com/kakao/varlog/internal/benchmark"
"github.com/kakao/varlog/internal/flags"
"github.com/kakao/varlog/pkg/types"
)
var (
flagClusterID = flags.ClusterID
flagTarget = &cli.StringSliceFlag{
Name: "target",
Category: "Common: ",
Required: true,
Usage: "The target of the benchmark load formatted by \"topic1:logstream1,topic2:logstream2,...<topic_id:logstream_id>\"",
}
flagMRAddrs = &cli.StringSliceFlag{
Name: "address",
Category: "Common: ",
Required: true,
}
flagDuration = &cli.DurationFlag{
Name: "duration",
Category: "Common: ",
Value: benchmark.DefaultDuration,
}
flagReportInterval = &cli.DurationFlag{
Name: "report-interval",
Category: "Common: ",
Value: benchmark.DefaultReportInterval,
}
flagPrintJSON = &cli.BoolFlag{
Name: "print-json",
Category: "Common: ",
Usage: "Print json output if it is set",
}
flagSingleConnPerTarget = &cli.BoolFlag{
Name: "single-conn-per-target",
Category: "Common: ",
Usage: "Use single connection shared by appenders in a target. Each target uses different connection.",
}
flagGopsAddr = &cli.StringFlag{
Name: "gops-addr",
Category: "Common: ",
Value: ":0",
Usage: "The address of gops agent",
}
flagAppenders = &cli.UintSliceFlag{
Name: "appenders",
Category: "Append: ",
Aliases: []string{"appenders-count"},
Value: cli.NewUintSlice(benchmark.DefaultConcurrency),
Usage: "The number of appenders for each load target",
}
flagMsgSize = &cli.UintSliceFlag{
Name: "message-size",
Category: "Append: ",
Aliases: []string{"msg-size"},
Value: cli.NewUintSlice(benchmark.DefaultMessageSize),
Usage: "Message sizes for each load target",
}
flagBatchSize = &cli.UintSliceFlag{
Name: "batch-size",
Category: "Append: ",
Value: cli.NewUintSlice(benchmark.DefaultBatchSize),
Usage: "Batch sizes for each load target",
}
flagPipelineSize = &cli.IntFlag{
Name: "pipeline-size",
Category: "Append: ",
Usage: "Pipeline size, no pipelined requests if zero. Not support per-target pipeline size yet.",
Value: 0,
}
flagSubscribers = &cli.UintSliceFlag{
Name: "subscribers",
Category: "Subscribe: ",
Aliases: []string{"subscribers-count"},
Value: cli.NewUintSlice(benchmark.DefaultConcurrency),
Usage: "The number of subscribers for each load target",
}
flagSubscribeSize = &cli.IntFlag{
Name: "subscribe-size",
Category: "Subscribe: ",
Usage: "The number of messages to subscribe at once",
Value: 1000,
}
)
func newCommandTest() *cli.Command {
return &cli.Command{
Name: "test",
Usage: "run benchmark test",
Flags: []cli.Flag{
flagClusterID,
flagTarget,
flagMRAddrs,
flagDuration,
flagReportInterval,
flagPrintJSON,
flagSingleConnPerTarget,
flagGopsAddr,
flagAppenders,
flagMsgSize,
flagBatchSize,
flagPipelineSize,
flagSubscribers,
flagSubscribeSize,
},
Action: runCommandTest,
}
}
func runCommandTest(c *cli.Context) error {
if c.NArg() > 0 {
return fmt.Errorf("unexpected args: %v", c.Args().Slice())
}
if err := agent.Listen(agent.Options{
Addr: c.String(flagGopsAddr.Name),
}); err != nil {
return err
}
defer agent.Close()
clusterID, err := types.ParseClusterID(c.String(flagClusterID.Name))
if err != nil {
return err
}
targets := make([]benchmark.Target, len(c.StringSlice(flagTarget.Name)))
for idx, str := range c.StringSlice(flagTarget.Name) {
toks := strings.Split(str, ":")
if len(toks) != 2 {
return fmt.Errorf("malformed target %s", str)
}
var target benchmark.Target
target.TopicID, err = types.ParseTopicID(toks[0])
if err != nil {
return fmt.Errorf("malformed target %s: invalid topic %s", str, toks[0])
}
if toks[1] != "*" {
target.LogStreamID, err = types.ParseLogStreamID(toks[1])
if err != nil {
return fmt.Errorf("malformed target %s: invalid log stream %s", str, toks[1])
}
}
target.PipelineSize = c.Int(flagPipelineSize.Name)
target.SubscribeSize = c.Int(flagSubscribeSize.Name)
targets[idx] = target
}
targets = setSizes(targets, c.UintSlice(flagMsgSize.Name), func(idx int, size uint) {
targets[idx].MessageSize = size
})
targets = setSizes(targets, c.UintSlice(flagBatchSize.Name), func(idx int, size uint) {
targets[idx].BatchSize = size
})
targets = setSizes(targets, c.UintSlice(flagAppenders.Name), func(idx int, size uint) {
targets[idx].AppendersCount = size
})
targets = setSizes(targets, c.UintSlice(flagSubscribers.Name), func(idx int, size uint) {
targets[idx].SubscribersCount = size
})
duration := c.Duration(flagDuration.Name)
reportInterval := c.Duration(flagReportInterval.Name)
var enc benchmark.ReportEncoder
if c.Bool(flagPrintJSON.Name) {
enc = benchmark.JsonEncoder{}
} else {
enc = benchmark.StringEncoder{}
}
opts := []benchmark.Option{
benchmark.WithClusterID(clusterID),
benchmark.WithTargets(targets...),
benchmark.WithMetadataRepository(c.StringSlice(flagMRAddrs.Name)),
benchmark.WithDuration(duration),
benchmark.WithReportInterval(reportInterval),
benchmark.WithReportEncoder(enc),
}
if c.Bool(flagSingleConnPerTarget.Name) {
opts = append(opts, benchmark.WithSingleConnPerTarget())
}
bm, err := benchmark.New(opts...)
if err != nil {
return err
}
defer func() {
_ = bm.Close()
}()
return bm.Run()
}
func setSizes(targets []benchmark.Target, sizes []uint, setter func(idx int, size uint)) []benchmark.Target {
for idx := range targets {
var size uint
if idx < len(sizes) {
size = sizes[idx]
} else {
size = sizes[len(sizes)-1]
}
setter(idx, size)
}
return targets
}