Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 155 lines (130 sloc) 5.626 kB
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
1 #!/usr/bin/env python
2 # -*-python-*-
3
4 """
5 Workload generator tool for Couchbase 2.0.
6 """
7
8 import pump_transfer
9 import pump
10 import pump_gen
11 import sys
12 import optparse
dea2bae @bcui6611 MB-7086: Add bin directory to python path
bcui6611 authored
13 import platform
14 import os
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
15
16 class WorkloadGen(pump_transfer.Transfer):
17 """Entry point for 2.0 cbworkloadgen."""
18
19 def __init__(self):
20 self.name = "cbworkloadgen"
21 self.source_alias = "generator"
22 self.sink_alias = "destination"
23
24 self.usage = \
25 "%prog [options]\n\n" \
26 "Generate workload to destination.\n\n" \
27 "Examples:\n" \
28 " %prog -n localhost:8091\n" \
29 " %prog -n 10.3.121.192:8091 -r .9 -i 100000 \\\n" \
30 " -s 100 -b my-other-bucket --threads=10\n\n"
31
32 def main(self, argv):
33
4ee17fd @bcui6611 MB-6740: Pass -v option to cbtransfer
bcui6611 authored
34 src, sink, common_opts, count_opts = self.opt_construct(argv)
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
35
36 local_args = [argv[0]]
37 local_args.append(src)
38 local_args.append(sink)
4ee17fd @bcui6611 MB-6740: Pass -v option to cbtransfer
bcui6611 authored
39 for v in common_opts.itervalues():
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
40 local_args.append(v[0])
41 local_args.append(v[1])
42
4ee17fd @bcui6611 MB-6740: Pass -v option to cbtransfer
bcui6611 authored
43 for v in count_opts.itervalues():
44 if v[1] is not None:
45 for i in range(v[1]):
46 local_args.append(v[0])
47
bcbe7d3 @bcui6611 MB-6867: Use os._exit() to handle exit
bcui6611 authored
48 return pump_transfer.Transfer.main(self, local_args)
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
49
50 def opt_construct(self, argv):
51 gen_opts = {"ratio_sets": "ratio-sets",
b26b857 @bcui6611 MB-6738: Use -l option to run nonstop
bcui6611 authored
52 "loop" : "exit-after-creates",
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
53 "max_items" : "max-items",
54 "size" : "min-value-size",
55 "prefix" : "prefix",
7186146 @bcui6611 CBD-542: Add JSON support to cbtransfer gen
bcui6611 authored
56 "json" : "json",
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
57 }
58
59 sink_opts = {"node" : "http://"}
60
61 common_opts = {"bucket" : ["-B", None],
62 "threads" : ["-t", None],
63 "username" : ["-u", None],
64 "password" : ["-p", None],
65 }
66
4ee17fd @bcui6611 MB-6740: Pass -v option to cbtransfer
bcui6611 authored
67 count_opts = {"verbose" : ["-v", None]}
68
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
69 p = optparse.OptionParser(usage=self.usage)
70 self.add_parser_options(p)
71 opts, rest = p.parse_args(argv[1:])
72
73 gen_str = "gen:"
74 for key in gen_opts.iterkeys():
75 val = getattr(opts, key, None)
b26b857 @bcui6611 MB-6738: Use -l option to run nonstop
bcui6611 authored
76 if val is not None:
77 if key in ("loop", "json"):
78 val = int(val)
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
79 gen_str += gen_opts[key] + "=" + str(val) + ","
80 if gen_str[-1] == ",":
81 gen_str = gen_str[:-1]
82 sink_str = ""
83 for key in sink_opts.iterkeys():
84 val = getattr(opts, key, None)
85 if val:
86 sink_str += sink_opts[key] + val
87
88 for key in common_opts.iterkeys():
89 val = getattr(opts, key, None)
90 if val:
91 common_opts[key][1] = str(val)
92
4ee17fd @bcui6611 MB-6740: Pass -v option to cbtransfer
bcui6611 authored
93 for key in count_opts.iterkeys():
94 val = getattr(opts, key, None)
95 if val:
96 count_opts[key][1] = int(val)
97
98 return gen_str, sink_str, common_opts, count_opts
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
99
100 def add_parser_options(self, p):
101 p.add_option("-r", "--ratio-sets",
102 action="store", type="float", default=.95,
7253381 @bcui6611 CBD-583: Show default values when printing help text
bcui6611 authored
103 metavar=".95",
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
104 help="""set/get operation ratio""")
105 p.add_option("-n", "--node", type="string", default="127.0.0.1:8091",
7253381 @bcui6611 CBD-583: Show default values when printing help text
bcui6611 authored
106 metavar="127.0.0.1:8091",
107 help="node's ns_server ip:port")
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
108 p.add_option("-b", "--bucket",
109 action="store", type="string", default="default",
7253381 @bcui6611 CBD-583: Show default values when printing help text
bcui6611 authored
110 metavar="default",
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
111 help="""insert data to a different bucket other than default """)
112 p.add_option("-i", "--max-items",
7253381 @bcui6611 CBD-583: Show default values when printing help text
bcui6611 authored
113 action="store", type="int", default=10000,
114 metavar="10000",
115 help="""number of items to be inserted""")
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
116 p.add_option("-s", "--size",
7253381 @bcui6611 CBD-583: Show default values when printing help text
bcui6611 authored
117 action="store", type="int", default=10,
118 metavar="10",
119 help="""minimum value size""")
b26b857 @bcui6611 MB-6738: Use -l option to run nonstop
bcui6611 authored
120 p.add_option("--prefix",
7253381 @bcui6611 CBD-583: Show default values when printing help text
bcui6611 authored
121 action="store", type="string", default="pymc",
122 metavar="pymc",
123 help="""prefix to use for memcached keys or json ids""")
7186146 @bcui6611 CBD-542: Add JSON support to cbtransfer gen
bcui6611 authored
124 p.add_option("-j", "--json",
b26b857 @bcui6611 MB-6738: Use -l option to run nonstop
bcui6611 authored
125 action="store_true", default=False,
7186146 @bcui6611 CBD-542: Add JSON support to cbtransfer gen
bcui6611 authored
126 help="""insert json data""")
b26b857 @bcui6611 MB-6738: Use -l option to run nonstop
bcui6611 authored
127 p.add_option("-l", "--loop",
128 action="store_false", default=True,
129 help="""loop forever until interrupted by users""")
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
130 p.add_option("-u", "--username",
131 action="store", type="string", default=None,
132 help="REST username for cluster or server node")
133 p.add_option("-p", "--password",
134 action="store", type="string", default=None,
135 help="REST password for cluster or server node")
136 p.add_option("-t", "--threads",
e55f204 @bcui6611 MB-6741: Set the default thread to 1
bcui6611 authored
137 action="store", type="int", default=1,
138 metavar="1",
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
139 help="""number of concurrent workers""")
140 p.add_option("-v", "--verbose",
141 action="count", default=0,
142 help="verbose logging; more -v's provide more verbosity")
143 return p
144
145
146 def find_handlers(self, opts, source, sink):
147 return pump_gen.GenSource, pump.PumpingStation.find_handler(opts, sink, pump_transfer.SINKS)
148
149 if __name__ == '__main__':
dea2bae @bcui6611 MB-7086: Add bin directory to python path
bcui6611 authored
150 if platform.system() == "Windows":
151 python_lib = os.path.join(os.path.dirname(sys.argv[0]), '..')
152 sys.path.append(python_lib)
153
bcbe7d3 @bcui6611 MB-6867: Use os._exit() to handle exit
bcui6611 authored
154 pump_transfer.exit_handler(WorkloadGen().main(sys.argv))
Something went wrong with that request. Please try again.