forked from VoltDB/voltdb-client-go
/
kv_config.go
107 lines (99 loc) · 3.84 KB
/
kv_config.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
/* This file is part of VoltDB.
* Copyright (C) 2008-2018 VoltDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VoltDB. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"errors"
"flag"
"fmt"
"time"
)
type runType string
// runTypes
const (
ASYNC runType = "async"
SYNC runType = "sync"
SQL runType = "sql"
)
func (p *runType) Set(s string) error {
*p = runType(s)
return nil
}
func (p *runType) String() string {
return fmt.Sprintf("%s", *p)
}
type kvConfig struct {
displayinterval time.Duration
duration time.Duration
warmup time.Duration
servers string
poolsize int
preload bool
getputratio float64
keysize int
minvaluesize int
maxvaluesize int
entropy int
usecompression bool
goroutines int
runtype runType
}
func newKVConfig() (*kvConfig, error) {
kv := new(kvConfig)
flag.DurationVar(&(kv.displayinterval), "displayinterval", 5*time.Second, "Interval for performance feedback, in seconds.")
flag.DurationVar(&(kv.duration), "duration", 120*time.Second, "Benchmark duration, in seconds.")
flag.DurationVar(&(kv.warmup), "warmup", 5*time.Second, "Benchmark duration, in seconds.")
flag.StringVar(&(kv.servers), "servers", "localhost:21212", "Comma separated list of the form server[:port] to connect to.")
flag.IntVar(&(kv.poolsize), "poolsize", 100000, "Number of keys to preload.")
flag.BoolVar(&(kv.preload), "preload", true, "Whether to preload a specified number of keys and values.")
flag.Float64Var(&(kv.getputratio), "getputratio", 0.90, "Fraction of ops that are gets (vs puts).")
flag.IntVar(&(kv.keysize), "keysize", 32, "Size of keys in bytes.")
flag.IntVar(&(kv.minvaluesize), "minvaluesize", 1024, "Minimum value size in bytes.")
flag.IntVar(&(kv.maxvaluesize), "maxvaluesize", 1024, "Maximum value size in bytes.")
flag.IntVar(&(kv.entropy), "entropy", 127, "Number of values considered for each value byte.")
flag.BoolVar(&(kv.usecompression), "usecompression", false, "Compress values on the client side.")
flag.IntVar(&(kv.goroutines), "goroutines", 20, "Number of concurrent goroutines synchronously calling procedures.")
flag.Var(&(kv.runtype), "runtype", "Type of the client calling procedures.")
flag.Parse()
if kv.runtype == "async" && kv.goroutines == 20 {
kv.goroutines = 2
}
// validate
switch {
case (kv.displayinterval <= 0):
return nil, errors.New("displayinterval must be > 0")
case (kv.duration <= 0):
return nil, errors.New("duration must be > 0")
case (kv.poolsize <= 0):
return nil, errors.New("poolsize must be > 0")
case (kv.getputratio < 0) || (kv.getputratio > 1):
return nil, errors.New("getputratio must be >= 0 and <= 1")
case (kv.keysize <= 0) || (kv.keysize > 250):
return nil, errors.New("keysize must be > 0 and <= 250")
case (kv.minvaluesize <= 0):
return nil, errors.New("minvaluesize must be > 0")
case (kv.maxvaluesize <= 0):
return nil, errors.New("maxvaluesize must be > 0")
case (kv.entropy <= 0) || (kv.entropy > 127):
return nil, errors.New("entropy must be > 0 and <= 127")
case (kv.goroutines <= 0):
return nil, errors.New("goroutines must be > 0")
case (kv.runtype != ASYNC) && (kv.runtype != SYNC) && (kv.runtype != SQL):
return nil, errors.New("runtype should be async,sync or sql")
default:
return kv, nil
}
}