Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 129 lines (107 sloc) 4.704 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",
7186146 @bcui6611 CBD-542: Add JSON support to cbtransfer gen
bcui6611 authored
49 "json" : "json",
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
50 }
51
52 sink_opts = {"node" : "http://"}
53
54 common_opts = {"bucket" : ["-B", None],
55 "threads" : ["-t", None],
56 "username" : ["-u", None],
57 "password" : ["-p", None],
58 }
59
60 p = optparse.OptionParser(usage=self.usage)
61 self.add_parser_options(p)
62 opts, rest = p.parse_args(argv[1:])
63
64 gen_str = "gen:"
65 for key in gen_opts.iterkeys():
66 val = getattr(opts, key, None)
67 if val:
68 gen_str += gen_opts[key] + "=" + str(val) + ","
69 if gen_str[-1] == ",":
70 gen_str = gen_str[:-1]
71
72 sink_str = ""
73 for key in sink_opts.iterkeys():
74 val = getattr(opts, key, None)
75 if val:
76 sink_str += sink_opts[key] + val
77
78 for key in common_opts.iterkeys():
79 val = getattr(opts, key, None)
80 if val:
81 common_opts[key][1] = str(val)
82
83 return gen_str, sink_str, common_opts
84
85 def add_parser_options(self, p):
86 p.add_option("-r", "--ratio-sets",
87 action="store", type="float", default=.95,
88 help="""set/get operation ratio""")
89 p.add_option("-n", "--node", type="string", default="127.0.0.1:8091",
90 help="node's ns_server ip:port")
91 p.add_option("-b", "--bucket",
92 action="store", type="string", default="default",
93 help="""insert data to a different bucket other than default """)
94 p.add_option("-i", "--max-items",
95 action="store", type="int", default=10000,
96 help="""number of items to be inserted""")
97 p.add_option("-s", "--size",
98 action="store", type="int", default=10,
99 help="""minimum value size""")
100 p.add_option("-P", "--prefix",
101 action="store", type="string", default="",
102 help="""prefix to use for memcached keys or json ids""")
7186146 @bcui6611 CBD-542: Add JSON support to cbtransfer gen
bcui6611 authored
103 p.add_option("-j", "--json",
104 action="store", type="int", default=0,
105 help="""insert json data""")
08cf400 @bcui6611 CBD-583: Reimplement cbworkloadgen with cbtransfer
bcui6611 authored
106 p.add_option("-e", "--exit-after-creates",
107 action="store", type="int", default=1,
108 help="""exit after creating items""")
109 p.add_option("-u", "--username",
110 action="store", type="string", default=None,
111 help="REST username for cluster or server node")
112 p.add_option("-p", "--password",
113 action="store", type="string", default=None,
114 help="REST password for cluster or server node")
115 p.add_option("-t", "--threads",
116 action="store", type="int", default=4,
117 help="""number of concurrent workers""")
118 p.add_option("-v", "--verbose",
119 action="count", default=0,
120 help="verbose logging; more -v's provide more verbosity")
121 return p
122
123
124 def find_handlers(self, opts, source, sink):
125 return pump_gen.GenSource, pump.PumpingStation.find_handler(opts, sink, pump_transfer.SINKS)
126
127 if __name__ == '__main__':
128 sys.exit(WorkloadGen().main(sys.argv))
Something went wrong with that request. Please try again.