forked from jaynavar/Copysets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplicationTest.py
More file actions
executable file
·91 lines (74 loc) · 2.03 KB
/
ReplicationTest.py
File metadata and controls
executable file
·91 lines (74 loc) · 2.03 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python2
import random
import timeit
# number of nodes in cluster
N = 5000
# number of chunks per node
C = 8000
# replication factor
R = 3
# total number of chunks in the system
T = N * C / R
# number of failed nodes
F = int(0.01 * N)
print "N=%d, C=%d, R=%d, T=%d, F=%d\n" % (N, C, R, T, F)
def countLoop():
count = 0
for _ in range(T):
count += 1
print "Count loop"
print timeit.timeit(countLoop, number=1)
print ""
def tupleSetAdd():
tuples = set()
for i in range(T):
tuples.add((i, i+1, i+2))
print "Adding tuples to set"
print timeit.timeit(tupleSetAdd, number=1)
print ""
def probOfDataLossShortcut():
nodes = range(N)
for _ in range(T):
if len([n for n in random.sample(nodes, R) if n < F]) == R:
return True
return False
print "Prob of data loss shortcut test"
print timeit.timeit(probOfDataLossShortcut, number=1)
print ""
def randomGeneration():
for _ in range(T):
copyset = []
while len(copyset) < R:
copyset = set([random.randint(0, N) for _ in range(R)])
print "Random generation"
print timeit.timeit(randomGeneration, number=1)
print ""
def randomSampling():
nodes = range(N)
for _ in range(T):
random.sample(nodes, R)
print "Random sampling"
print timeit.timeit(randomSampling, number=1)
print ""
def generateCopysets():
copysets = set()
nodes = range(N)
for _ in range(T):
copysets.add(tuple(sorted(random.sample(nodes, R))))
print "Random copyset generation"
print timeit.timeit(generateCopysets, number=1)
print ""
def generateCopysetsWithCapacities():
copysets = set()
capacities = {nodeId: C for nodeId in range(N)}
for _ in range(int(0.8 * T)):
copyset = random.sample(capacities.keys(), R)
copysets.add(tuple(sorted(copyset)))
# decrement node capacities
for node in copyset:
capacities[node] -= 1
if capacities[node] == 0:
del capacities[node]
print "Random copyset generation with capacities"
print timeit.timeit(generateCopysetsWithCapacities, number=1)
print ""