Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 125 lines (103 sloc) 4.52 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
13
14 class WorkloadGen(pump_transfer.Transfer):
15 """Entry point for 2.0 cbworkloadgen."""
16
17 def __init__(self):
18 self.name = "cbworkloadgen"
19 self.source_alias = "generator"
20 self.sink_alias = "destination"
21
22 self.usage = \
23 "%prog [options]\n\n" \
24 "Generate workload to destination.\n\n" \
25 "Examples:\n" \
26 " %prog -n localhost:8091\n" \
27 " %prog -n 10.3.121.192:8091 -r .9 -i 100000 \\\n" \
28 " -s 100 -b my-other-bucket --threads=10\n\n"
29
30 def main(self, argv):
31
32 src, sink, common_opts = self.opt_construct(argv)
33
34 local_args = [argv[0]]
35 local_args.append(src)
36 local_args.append(sink)
37 for k, v in common_opts.iteritems():
38 local_args.append(v[0])
39 local_args.append(v[1])
40
41 pump_transfer.Transfer.main(self, local_args)
42
43 def opt_construct(self, argv):
44 gen_opts = {"ratio_sets": "ratio-sets",
45 "exit_after_creates" : "exit-after-creates",
46 "max_items" : "max-items",
47 "size" : "min-value-size",
48 "prefix" : "prefix",
49 }
50
51 sink_opts = {"node" : "http://"}
52
53 common_opts = {"bucket" : ["-B", None],
54 "threads" : ["-t", None],
55 "username" : ["-u", None],
56 "password" : ["-p", None],
57 }
58
59 p = optparse.OptionParser(usage=self.usage)
60 self.add_parser_options(p)
61 opts, rest = p.parse_args(argv[1:])
62
63 gen_str = "gen:"
64 for key in gen_opts.iterkeys():
65 val = getattr(opts, key, None)
66 if val:
67 gen_str += gen_opts[key] + "=" + str(val) + ","
68 if gen_str[-1] == ",":
69 gen_str = gen_str[:-1]
70
71 sink_str = ""
72 for key in sink_opts.iterkeys():
73 val = getattr(opts, key, None)
74 if val:
75 sink_str += sink_opts[key] + val
76
77 for key in common_opts.iterkeys():
78 val = getattr(opts, key, None)
79 if val:
80 common_opts[key][1] = str(val)
81
82 return gen_str, sink_str, common_opts
83
84 def add_parser_options(self, p):
85 p.add_option("-r", "--ratio-sets",
86 action="store", type="float", default=.95,
87 help="""set/get operation ratio""")
88 p.add_option("-n", "--node", type="string", default="127.0.0.1:8091",
89 help="node's ns_server ip:port")
90 p.add_option("-b", "--bucket",
91 action="store", type="string", default="default",
92 help="""insert data to a different bucket other than default """)
93 p.add_option("-i", "--max-items",
94 action="store", type="int", default=10000,
95 help="""number of items to be inserted""")
96 p.add_option("-s", "--size",
97 action="store", type="int", default=10,
98 help="""minimum value size""")
99 p.add_option("-P", "--prefix",
100 action="store", type="string", default="",
101 help="""prefix to use for memcached keys or json ids""")
102 p.add_option("-e", "--exit-after-creates",
103 action="store", type="int", default=1,
104 help="""exit after creating items""")
105 p.add_option("-u", "--username",
106 action="store", type="string", default=None,
107 help="REST username for cluster or server node")
108 p.add_option("-p", "--password",
109 action="store", type="string", default=None,
110 help="REST password for cluster or server node")
111 p.add_option("-t", "--threads",
112 action="store", type="int", default=4,
113 help="""number of concurrent workers""")
114 p.add_option("-v", "--verbose",
115 action="count", default=0,
116 help="verbose logging; more -v's provide more verbosity")
117 return p
118
119
120 def find_handlers(self, opts, source, sink):
121 return pump_gen.GenSource, pump.PumpingStation.find_handler(opts, sink, pump_transfer.SINKS)
122
123 if __name__ == '__main__':
124 sys.exit(WorkloadGen().main(sys.argv))
Something went wrong with that request. Please try again.