Skip to content
Browse files

CBD-542: Add JSON support to cbtransfer gen

Change-Id: I0090922fa56e2b027bc7c103be5e6b622b276362
Reviewed-on: http://review.couchbase.org/20968
Tested-by: Bin Cui <bin.cui@gmail.com>
Reviewed-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information...
1 parent 19a3187 commit 7186146e5b5fe8741c3bfc85481156a7e512574a @bcui6611 bcui6611 committed with Peter Wansch Sep 25, 2012
Showing with 19 additions and 5 deletions.
  1. +4 −0 cbworkloadgen
  2. +15 −5 pump_gen.py
View
4 cbworkloadgen
@@ -46,6 +46,7 @@ class WorkloadGen(pump_transfer.Transfer):
"max_items" : "max-items",
"size" : "min-value-size",
"prefix" : "prefix",
+ "json" : "json",
}
sink_opts = {"node" : "http://"}
@@ -99,6 +100,9 @@ class WorkloadGen(pump_transfer.Transfer):
p.add_option("-P", "--prefix",
action="store", type="string", default="",
help="""prefix to use for memcached keys or json ids""")
+ p.add_option("-j", "--json",
+ action="store", type="int", default=0,
+ help="""insert json data""")
p.add_option("-e", "--exit-after-creates",
action="store", type="int", default=1,
help="""exit after creating items""")
View
20 pump_gen.py
@@ -3,7 +3,6 @@
import memcacheConstants
import pump
-
class GenSource(pump.Source):
"""Generates simple SET/GET workload, useful for basic testing.
Examples:
@@ -51,7 +50,8 @@ def parse_spec(opts, spec):
'max-items': 10000,
'min-value-size': 10,
'prefix': "",
- 'ratio-sets': 0.05}
+ 'ratio-sets': 0.05,
+ 'json': 0}
for kv in spec[len("gen:"):].split(','):
if kv:
k = kv.split('=')[0].strip()
@@ -81,8 +81,14 @@ def provide_batch(self):
max_items = cfg['max-items']
ratio_sets = cfg['ratio-sets']
exit_after_creates = cfg['exit-after-creates']
+ json = cfg['json']
if not self.body:
- self.body = "0" * cfg['min-value-size']
+ min_value_body = "0" * cfg['min-value-size']
+ if json:
+ self.body = '{"name": "%s%s", "age": %s, "index": %s,' + \
+ ' "min_value_size": "%s"}' % min_value_body
+ else:
+ self.body = min_value_body
batch = pump.Batch(self)
@@ -108,8 +114,12 @@ def provide_batch(self):
key = self.cur_gets % self.cur_items
self.cur_ops = self.cur_ops + 1
- msg = (cmd, vbucket_id, prefix + str(key), flg, exp, cas, '', self.body)
- batch.append(msg, len(self.body))
+ if json:
+ value = self.body % (prefix, key, key % 101, key)
+ else:
+ value = self.body
+ msg = (cmd, vbucket_id, prefix + str(key), flg, exp, cas, '', value)
+ batch.append(msg, len(value))
if exit_after_creates and self.cur_items >= max_items:
self.done = True

0 comments on commit 7186146

Please sign in to comment.
Something went wrong with that request. Please try again.