-
Notifications
You must be signed in to change notification settings - Fork 8
/
cbworkloadgen
executable file
·154 lines (130 loc) · 5.49 KB
/
cbworkloadgen
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
#!/usr/bin/env python
# -*-python-*-
"""
Workload generator tool for Couchbase 2.0.
"""
import pump_transfer
import pump
import pump_gen
import sys
import optparse
import platform
import os
class WorkloadGen(pump_transfer.Transfer):
"""Entry point for 2.0 cbworkloadgen."""
def __init__(self):
self.name = "cbworkloadgen"
self.source_alias = "generator"
self.sink_alias = "destination"
self.usage = \
"%prog [options]\n\n" \
"Generate workload to destination.\n\n" \
"Examples:\n" \
" %prog -n localhost:8091\n" \
" %prog -n 10.3.121.192:8091 -r .9 -i 100000 \\\n" \
" -s 100 -b my-other-bucket --threads=10\n\n"
def main(self, argv):
src, sink, common_opts, count_opts = self.opt_construct(argv)
local_args = [argv[0]]
local_args.append(src)
local_args.append(sink)
for v in common_opts.itervalues():
local_args.append(v[0])
local_args.append(v[1])
for v in count_opts.itervalues():
if v[1] is not None:
for i in range(v[1]):
local_args.append(v[0])
return pump_transfer.Transfer.main(self, local_args)
def opt_construct(self, argv):
gen_opts = {"ratio_sets": "ratio-sets",
"loop" : "exit-after-creates",
"max_items" : "max-items",
"size" : "min-value-size",
"prefix" : "prefix",
"json" : "json",
}
sink_opts = {"node" : "http://"}
common_opts = {"bucket" : ["-B", None],
"threads" : ["-t", None],
"username" : ["-u", None],
"password" : ["-p", None],
}
count_opts = {"verbose" : ["-v", None]}
p = optparse.OptionParser(usage=self.usage)
self.add_parser_options(p)
opts, rest = p.parse_args(argv[1:])
gen_str = "gen:"
for key in gen_opts.iterkeys():
val = getattr(opts, key, None)
if val is not None:
if key in ("loop", "json"):
val = int(val)
gen_str += gen_opts[key] + "=" + str(val) + ","
if gen_str[-1] == ",":
gen_str = gen_str[:-1]
sink_str = ""
for key in sink_opts.iterkeys():
val = getattr(opts, key, None)
if val:
sink_str += sink_opts[key] + val
for key in common_opts.iterkeys():
val = getattr(opts, key, None)
if val:
common_opts[key][1] = str(val)
for key in count_opts.iterkeys():
val = getattr(opts, key, None)
if val:
count_opts[key][1] = int(val)
return gen_str, sink_str, common_opts, count_opts
def add_parser_options(self, p):
p.add_option("-r", "--ratio-sets",
action="store", type="float", default=.95,
metavar=".95",
help="""set/get operation ratio""")
p.add_option("-n", "--node", type="string", default="127.0.0.1:8091",
metavar="127.0.0.1:8091",
help="node's ns_server ip:port")
p.add_option("-b", "--bucket",
action="store", type="string", default="default",
metavar="default",
help="""insert data to a different bucket other than default """)
p.add_option("-i", "--max-items",
action="store", type="int", default=10000,
metavar="10000",
help="""number of items to be inserted""")
p.add_option("-s", "--size",
action="store", type="int", default=10,
metavar="10",
help="""minimum value size""")
p.add_option("--prefix",
action="store", type="string", default="pymc",
metavar="pymc",
help="""prefix to use for memcached keys or json ids""")
p.add_option("-j", "--json",
action="store_true", default=False,
help="""insert json data""")
p.add_option("-l", "--loop",
action="store_false", default=True,
help="""loop forever until interrupted by users""")
p.add_option("-u", "--username",
action="store", type="string", default=None,
help="REST username for cluster or server node")
p.add_option("-p", "--password",
action="store", type="string", default=None,
help="REST password for cluster or server node")
p.add_option("-t", "--threads",
action="store", type="int", default=1,
metavar="1",
help="""number of concurrent workers""")
p.add_option("-v", "--verbose",
action="count", default=0,
help="verbose logging; more -v's provide more verbosity")
return p
def find_handlers(self, opts, source, sink):
return pump_gen.GenSource, pump.PumpingStation.find_handler(opts, sink, pump_transfer.SINKS)
if __name__ == '__main__':
if platform.system() == "Windows":
python_lib = os.path.join(os.path.dirname(sys.argv[0]), '..')
sys.path.append(python_lib)
pump_transfer.exit_handler(WorkloadGen().main(sys.argv))