forked from jaynavar/Copysets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain_Figure6.py
More file actions
executable file
·193 lines (173 loc) · 6.65 KB
/
Copy pathMain_Figure6.py
File metadata and controls
executable file
·193 lines (173 loc) · 6.65 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python2
import argparse
import Facebook
from ExperimentTrack import ExperimentTrack
import Hdfs
import matplotlib
import numpy as np
import os
import Ramcloud
DEBUG = False
RENDER_LOCAL = False
RANDOM_REPLICATION_SCHEMES = [
Hdfs.HdfsRandomScheme,
Ramcloud.RamcloudRandomScheme,
Facebook.FacebookRandomScheme,
]
COPYSET_REPLICATION_SCHEMES = [
Hdfs.HdfsCopysetScheme,
Facebook.FacebookCopysetScheme,
Ramcloud.RamcloudCopysetScheme,
]
ALL_REPLICATION_SCHEMES = RANDOM_REPLICATION_SCHEMES + COPYSET_REPLICATION_SCHEMES
SCHEME_PLOT_INFOS = [(scheme.__name__, scheme.plotInfo())
for scheme in ALL_REPLICATION_SCHEMES]
def runFigure6Experiment(rf=3, maxNodes=10000, simulation=False, trials=100,
sampleGap=1):
# can't have less than replication factor number of nodes
minNodes = rf
# gather the data from the replication schemes
replicationKwargs = {'debug': DEBUG, 'simulation': simulation,
'trials': trials, 'replicationFactor': 3}
validReplicationSchemes = ALL_REPLICATION_SCHEMES
replicationSchemes = [scheme(**replicationKwargs)
for scheme in validReplicationSchemes]
data = {}
for scheme in replicationSchemes:
print 'Collecting data for: %s\n' % type(scheme).__name__
results = []
for numNodes in range(0, maxNodes + 1, sampleGap):
if numNodes < minNodes:
result = 0
else:
result = scheme.probabilityOfDataLoss(numNodes)
results.append((numNodes, result))
if DEBUG:
print 'N=%d, P=%0.3f' % (numNodes, result)
data[type(scheme).__name__] = results
print ''
return data
def generateDiagram(data, groupSize=500):
def outputDataPoints(dataPoints):
# output stats for the group
firstN = dataPoints[0][0]
lastN = dataPoints[-1][0]
npDataPoints = np.array([dp[1] for dp in dataPoints])
avg = npDataPoints.mean()
std = npDataPoints.std()
print ('N=(%d,%d), AVG_PR=%0.3f, STD_PR=%0.3f' %
(firstN, lastN, avg, std))
# print average probabilities for groups of data points
for key, schemePlotInfo in SCHEME_PLOT_INFOS:
if key not in data:
continue
schemeName = schemePlotInfo.label
print 'Scheme: %s' % schemeName
dataPoints = []
minNumNodes = None
for numNodes, prob in data[key]:
if minNumNodes == None:
minNumNodes = numNodes
if numNodes - minNumNodes >= groupSize:
outputDataPoints(dataPoints)
# reset state
dataPoints = []
minNumNodes = numNodes
dataPoints.append((numNodes, prob))
if dataPoints:
outputDataPoints(dataPoints)
print ''
def generateFigure6(data, et, simulation=False, sampleGap=1, maxNodes=10000):
# set dimensions and title
fig = plt.figure(figsize=(8, 5))
fig.suptitle('Probability of data loss when 1% of the nodes fail concurrently')
# add data
for key, schemePlotInfo in SCHEME_PLOT_INFOS:
if key not in data:
continue
spi = schemePlotInfo
x, y = zip(*data[key])
# mark every 1,000 ticks, regardless of sample gap
markevery = int(1000 / sampleGap)
plt.plot(x, y, label=spi.label, linestyle=spi.linestyle,
linewidth=spi.linewidth, marker=spi.marker,
markevery=markevery, markersize=spi.markersize,
markeredgewidth=spi.markeredgewidth,
color=spi.color, clip_on=spi.clip_on)
# add legend
if maxNodes < 5000:
plt.legend(numpoints=1, handlelength=0.5, borderaxespad=1.0,
loc='center right', fontsize='medium')
else:
plt.legend(numpoints=1, handlelength=0.5, borderaxespad=1.0)
# set x-axis
plt.xlabel('Number of nodes')
# set y-axis
plt.ylabel('Probability of data loss')
yticksRange = np.arange(0.0, 1.0 + 0.1, 0.2)
plt.yticks(yticksRange)
ax = plt.gca()
ax.set_yticklabels(['{:,.0%}'.format(tick) for tick in yticksRange])
# save figure
if RENDER_LOCAL:
plt.show()
else:
if et.save:
if simulation:
filename = 'Figure6_simulation.png'
else:
filename = 'Figure6_computation.png'
plt.savefig(os.path.join(et.getDirName(), filename))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true',
help='enable debugging output')
parser.add_argument('-s', '--save', action='store_true',
help='location to save data to')
parser.add_argument('-l', '--load',
help='location to load data from')
parser.add_argument('--note', default='N/A',
help='add comment to trial info')
parser.add_argument('-g', '--group-size', default='500',
help='size of debug summary groups')
parser.add_argument('--sample-gap', default='1',
help='gap between sampled datapoints')
parser.add_argument('--max-nodes', default='10000',
help='maximum number of nodes')
parser.add_argument('--simulation', action='store_true',
help='use simulation instead of computation')
parser.add_argument('-t', '--trials', default='100',
help='number of simulation trials to run per datapoint')
parser.add_argument('--no-figures', action='store_true',
help='do not generate figures')
parser.add_argument('-r', '--render-local', action='store_true',
help='render figure locally using X11')
args = parser.parse_args()
RENDER_LOCAL = args.render_local
if not RENDER_LOCAL:
matplotlib.use('Agg')
import matplotlib.pyplot as plt
DEBUG = args.debug
trialInfo = [
'Trial Note: %s' % args.note,
'',
'Trials: %s' % args.trials,
'Simulation: %r' % args.simulation,
'Sample gap: %s' % args.sample_gap,
'Max nodes: %s' % args.max_nodes,
]
et = ExperimentTrack('data_Figure6', trialInfo, args.save)
if args.load:
data = et.loadData(args.load)
else:
data = runFigure6Experiment(maxNodes=int(args.max_nodes),
simulation=args.simulation,
trials=int(args.trials),
sampleGap=int(args.sample_gap))
generateDiagram(data, groupSize=int(args.group_size))
et.dumpData(data)
if not args.no_figures:
generateFigure6(data, et, simulation=args.simulation,
sampleGap=int(args.sample_gap),
maxNodes=int(args.max_nodes))
et.setCleanExit()