Skip to content

Commit 50b9eb7

Browse files
committed
multiget benchmark improvement
1 parent b064f42 commit 50b9eb7

2 files changed

Lines changed: 51 additions & 40 deletions

File tree

riak/benchmarks/multiget.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import binascii
2+
import os
3+
4+
import riak.benchmark as benchmark
5+
6+
from riak import RiakClient
7+
from multiprocessing import cpu_count
8+
9+
nodes = [
10+
('riak-test', 8098, 8087),
11+
# ('riak-test', 10018, 10017),
12+
# ('riak-test', 10028, 10027),
13+
# ('riak-test', 10038, 10037),
14+
# ('riak-test', 10048, 10047),
15+
# ('riak-test', 10058, 10057),
16+
]
17+
client = RiakClient(
18+
nodes=nodes,
19+
protocol='pbc',
20+
multiget_pool_size=128)
21+
22+
bkeys = [('default', 'multiget', str(key)) for key in range(10000)]
23+
24+
data = binascii.b2a_hex(os.urandom(1024))
25+
26+
print("Benchmarking multiget:")
27+
print(" CPUs: {0}".format(cpu_count()))
28+
print(" Threads: {0}".format(client._multiget_pool._size))
29+
print(" Keys: {0}".format(len(bkeys)))
30+
print()
31+
32+
with benchmark.measure() as b:
33+
with b.report('populate'):
34+
for _, bucket, key in bkeys:
35+
client.bucket(bucket).new(key, encoded_data=data,
36+
content_type='text/plain'
37+
).store()
38+
for b in benchmark.measure_with_rehearsal():
39+
# client.protocol = 'http'
40+
# with b.report('http seq'):
41+
# for _, bucket, key in bkeys:
42+
# client.bucket(bucket).get(key)
43+
# with b.report('http multi'):
44+
# client.multiget(bkeys)
45+
46+
client.protocol = 'pbc'
47+
with b.report('pbc seq'):
48+
for _, bucket, key in bkeys:
49+
client.bucket(bucket).get(key)
50+
with b.report('pbc multi'):
51+
client.multiget(bkeys)

riak/client/multiget.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -201,43 +201,3 @@ def multiget(client, keys, **options):
201201
outq.task_done()
202202

203203
return results
204-
205-
if __name__ == '__main__':
206-
# Run a benchmark!
207-
from riak import RiakClient
208-
import riak.benchmark as benchmark
209-
client = RiakClient(protocol='pbc')
210-
bkeys = [('default', 'multiget', str(key)) for key in range(10000)]
211-
212-
data = None
213-
with open(__file__) as f:
214-
data = f.read()
215-
216-
print("Benchmarking multiget:")
217-
print(" CPUs: {0}".format(cpu_count()))
218-
print(" Threads: {0}".format(POOL_SIZE))
219-
print(" Keys: {0}".format(len(bkeys)))
220-
print()
221-
222-
with benchmark.measure() as b:
223-
with b.report('populate'):
224-
for _, bucket, key in bkeys:
225-
client.bucket(bucket).new(key, encoded_data=data,
226-
content_type='text/plain'
227-
).store()
228-
for b in benchmark.measure_with_rehearsal():
229-
client.protocol = 'http'
230-
with b.report('http seq'):
231-
for _, bucket, key in bkeys:
232-
client.bucket(bucket).get(key)
233-
234-
with b.report('http multi'):
235-
multiget(client, bkeys)
236-
237-
client.protocol = 'pbc'
238-
with b.report('pbc seq'):
239-
for _, bucket, key in bkeys:
240-
client.bucket(bucket).get(key)
241-
242-
with b.report('pbc multi'):
243-
multiget(client, bkeys)

0 commit comments

Comments
 (0)