-
Notifications
You must be signed in to change notification settings - Fork 38
/
benchmark.py
68 lines (57 loc) · 1.68 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from nydus.db import create_cluster
import time
partition_cluster = create_cluster({
'engine': 'nydus.db.backends.redis.Redis',
'router': 'nydus.db.routers.keyvalue.PartitionRouter',
'hosts': {
0: {'db': 0},
1: {'db': 1},
2: {'db': 2},
3: {'db': 3},
},
})
ketama_cluster = create_cluster({
'engine': 'nydus.db.backends.redis.Redis',
'router': 'nydus.db.routers.keyvalue.ConsistentHashingRouter',
'hosts': {
0: {'db': 0},
1: {'db': 1},
2: {'db': 2},
3: {'db': 3},
},
})
roundrobin_cluster = create_cluster({
'engine': 'nydus.db.backends.redis.Redis',
'router': 'nydus.db.routers.RoundRobinRouter',
'hosts': {
0: {'db': 0},
1: {'db': 1},
2: {'db': 2},
3: {'db': 3},
},
})
def test_redis_normal(cluster):
cluster.set('foo', 'bar')
cluster.get('foo')
cluster.set('biz', 'bar')
cluster.get('biz')
cluster.get('bar')
def test_redis_map(cluster):
with cluster.map() as conn:
for n in xrange(5):
conn.set('foo', 'bar')
conn.get('foo')
conn.set('biz', 'bar')
conn.get('biz')
conn.get('bar')
def main(iterations=1000):
for cluster in ('partition_cluster', 'ketama_cluster', 'roundrobin_cluster'):
for func in ('test_redis_normal', 'test_redis_map'):
print "Running %r on %r" % (func, cluster)
s = time.time()
for x in xrange(iterations):
globals()[func](globals()[cluster])
t = (time.time() - s) * 1000
print " %.3fms per iteration" % (t / iterations,)
if __name__ == '__main__':
main()