8
from urllib.parse import urlparse
10
from collections import defaultdict
14
Run JSON benchmark for 3 commands:
18
We want to the overall time it takes
19
to save and access keys that contains
20
JSON values with this benchmark.
21
This also verify that the basic functionalities
22
for using JSON types work correctly
29
key = "json-{}".format(i)
30
r.execute_command('JSON.SET', key, '.', '{"a":123456, "b": "hello", "nested": {"abc": "ffffff", "bfb": null}}')
34
key = "json-{}".format(i)
35
r.execute_command('JSON.GET', key, '$.a', '$..abc')
38
key = "json-{}".format(i)
39
r.execute_command('JSON.TYPE', key, '$.a')
43
print( '{} '.format(wpid))
45
rep = defaultdict(int)
46
r = redis.StrictRedis(host=ctx['host'], port=ctx['port'])
48
if ctx['pipeline'] == 0:
49
total_count = int(ctx['count'])
50
for i in range(0, total_count):
54
bin = int(math.floor(s1 * 1000)) + 1
56
for i in range(0, total_count):
60
bin = int(math.floor(s1 * 1000)) + 1
62
for i in range(0, total_count):
66
bin = int(math.floor(s1 * 1000)) + 1
69
for i in range(0, ctx['count'], ctx['pipeline']):
72
for j in range(0, ctx['pipeline']):
76
bin = int(math.floor(s1 * 1000)) + 1
77
rep[bin] += ctx['pipeline']
81
if __name__ == '__main__':
82
parser = argparse.ArgumentParser(description='ReJSON Benchmark', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
83
parser.add_argument('-c', '--count', type=int, default=100000, help='total number of operations')
84
parser.add_argument('-p', '--pipeline', type=int, default=0, help='pipeline size')
85
parser.add_argument('-w', '--workers', type=int, default=8, help='number of worker processes')
86
parser.add_argument('-u', '--uri', type=str, default='redis://localhost:6379', help='Redis server URI')
87
args = parser.parse_args()
88
uri = urlparse(args.uri)
90
r = redis.Redis(host=uri.hostname, port=uri.port)
92
pool = multiprocessing.Pool(args.workers)
95
'count': args.count / args.workers,
96
'pipeline': args.pipeline,
102
print ('Starting workers: ')
103
p = multiprocessing.Pool(args.workers)
104
results = p.map(runWorker, (ctx, ) * args.workers)
108
s1 = time.time() - s0
109
agg = defaultdict(int)
111
for k, v in res.items():
115
count = args.count * 3
116
print (f'Count: {args.count}, Workers: {args.workers}, Pipeline: {args.pipeline}')
117
print (f'Using hireds: {redis.utils.HIREDIS_AVAILABLE}')
118
print (f'Runtime: {round(s1, 2):,} seconds')
119
print (f'Throughput: {round(count/s1, 2):,} requests per second')
120
for k, v in sorted(agg.items()):
121
perc = 100.0 * v / count
122
print (f'{perc:.4f}% <= {k:,} milliseconds')