-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
49 lines (36 loc) · 1.21 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gc
import itertools
import time
import click
from redis.client import StrictRedis
from kafkaesque.topic import Topic
@click.command()
@click.option('--batch-size', type=click.INT, default=1)
@click.option('--page-size', type=click.INT, default=2 ** 16)
@click.option('--payload-length', type=click.INT, default=1024)
@click.option('-c', '--count', type=click.INT, default=None)
@click.option('-t', '--topic', default='benchmark')
def benchmark(count, topic, batch_size, page_size, payload_length):
client = StrictRedis()
batch = ["x" * payload_length] * batch_size
topic = Topic(client, topic)
try:
topic.create(page_size)
except Exception:
pass
gc.disable()
start = time.time()
generator = xrange(1, count + 1) if count else itertools.count(1)
i = 0
try:
for i in generator:
topic.produce(batch)
if i % 100 == 0:
print 'Produced', i, 'batches.'
except KeyboardInterrupt:
pass
end = time.time()
print 'Produced', i * batch_size, payload_length / 1024.0, 'KB records in', end - start, 'seconds'
print (i * batch_size) / (end - start), 'messages/sec'
if __name__ == '__main__':
benchmark()