Adding multidimensional simulator and results module to gather data for visualization.
This commit is contained in:
parent
e8e82d7460
commit
bf1a5a60e4
|
@ -2,29 +2,49 @@
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
|
|
||||||
blockSize = 0
|
|
||||||
failureRateStep = 0
|
|
||||||
maxTries = 0
|
|
||||||
numberValidators = 0
|
|
||||||
chi = 0
|
|
||||||
failureRate = 0
|
|
||||||
deterministic = 0
|
deterministic = 0
|
||||||
|
blockSize = 0
|
||||||
|
numberValidators = 0
|
||||||
|
failureRate = 0
|
||||||
|
failureRateStart = 0
|
||||||
|
failureRateStop = 0
|
||||||
|
failureRateStep = 0
|
||||||
|
chio = 0
|
||||||
|
chiStart = 0
|
||||||
|
chiStop = 0
|
||||||
|
chiStep = 0
|
||||||
|
run =0
|
||||||
|
runStart = 0
|
||||||
|
runStop = 0
|
||||||
|
runStep = 0
|
||||||
|
|
||||||
|
def __init__(self, deterministic, blockSize, numberValidators,\
|
||||||
|
failureRateStart, failureRateStop, failureRateStep,\
|
||||||
|
chiStart, chiStop, chiStep,\
|
||||||
|
runStart, runStop, runStep):
|
||||||
|
|
||||||
def __init__(self, blockSize, failureRateStep, maxTries, numberValidators, chi, failureRate, deterministic):
|
|
||||||
if numberValidators < (blockSize*4):
|
if numberValidators < (blockSize*4):
|
||||||
print("ERROR: The number of validators cannot be lower than the block size * 4")
|
print("ERROR: The number of validators cannot be lower than the block size * 4")
|
||||||
exit(1)
|
exit(1)
|
||||||
if chi < 1:
|
if chiStart < 1:
|
||||||
print("Chi has to be greater than 0")
|
print("Chi has to be greater than 0")
|
||||||
exit(1)
|
exit(1)
|
||||||
if chi > blockSize:
|
if chiStop > blockSize:
|
||||||
print("Chi has to be smaller than %d" % blockSize)
|
print("Chi has to be smaller than %d" % blockSize)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
self.blockSize = blockSize
|
|
||||||
self.failureRateStep = failureRateStep
|
|
||||||
self.maxTries = maxTries
|
|
||||||
self.numberValidators = numberValidators
|
|
||||||
self.chi = chi
|
|
||||||
self.failureRate = failureRate
|
|
||||||
self.deterministic = deterministic
|
self.deterministic = deterministic
|
||||||
|
self.blockSize = blockSize
|
||||||
|
self.numberValidators = numberValidators
|
||||||
|
self.failureRateStart = failureRateStart
|
||||||
|
self.failureRateStop = failureRateStop
|
||||||
|
self.failureRateStep = failureRateStep
|
||||||
|
self.failureRate = failureRateStart
|
||||||
|
self.chiStart = chiStart
|
||||||
|
self.chiStop = chiStop
|
||||||
|
self.chiStep = chiStep
|
||||||
|
self.chi = chiStart
|
||||||
|
self.runStart = runStart
|
||||||
|
self.runStop = runStop
|
||||||
|
self.runStep = runStep
|
||||||
|
self.run = runStart
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/python3
|
||||||
|
|
||||||
|
|
||||||
|
class Result:
|
||||||
|
|
||||||
|
config = []
|
||||||
|
missingVector = []
|
||||||
|
blockAvailable = -1
|
||||||
|
|
||||||
|
def __init__(self, config):
|
||||||
|
self.config = config
|
||||||
|
self.blockAvailable = -1
|
||||||
|
self.missingVector = []
|
||||||
|
|
||||||
|
|
||||||
|
def addMissing(self, missingVector):
|
||||||
|
self.missingVector = missingVector
|
|
@ -4,6 +4,7 @@ import networkx as nx
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from DAS.tools import *
|
from DAS.tools import *
|
||||||
|
from DAS.results import *
|
||||||
from DAS.observer import *
|
from DAS.observer import *
|
||||||
from DAS.validator import *
|
from DAS.validator import *
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ class Simulator:
|
||||||
logLevel = logging.INFO
|
logLevel = logging.INFO
|
||||||
validators = []
|
validators = []
|
||||||
glob = []
|
glob = []
|
||||||
|
result = []
|
||||||
config = []
|
config = []
|
||||||
logger = []
|
logger = []
|
||||||
format = {}
|
format = {}
|
||||||
|
@ -20,6 +22,7 @@ class Simulator:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.format = {"entity": "Simulator"}
|
self.format = {"entity": "Simulator"}
|
||||||
|
self.result = Result(self.config)
|
||||||
|
|
||||||
def initValidators(self):
|
def initValidators(self):
|
||||||
if not self.config.deterministic:
|
if not self.config.deterministic:
|
||||||
|
@ -48,7 +51,7 @@ class Simulator:
|
||||||
for id in range(self.config.blockSize):
|
for id in range(self.config.blockSize):
|
||||||
G = nx.random_regular_graph(d, len(rowChannels[id]))
|
G = nx.random_regular_graph(d, len(rowChannels[id]))
|
||||||
if not nx.is_connected(G):
|
if not nx.is_connected(G):
|
||||||
self.logger.error("graph not connected for row %d !" % id, extra=self.format)
|
self.logger.error("Graph not connected for row %d !" % id, extra=self.format)
|
||||||
for u, v in G.edges:
|
for u, v in G.edges:
|
||||||
val1=rowChannels[id][u]
|
val1=rowChannels[id][u]
|
||||||
val2=rowChannels[id][v]
|
val2=rowChannels[id][v]
|
||||||
|
@ -56,7 +59,7 @@ class Simulator:
|
||||||
val2.rowNeighbors[id].append(val1)
|
val2.rowNeighbors[id].append(val1)
|
||||||
G = nx.random_regular_graph(d, len(columnChannels[id]))
|
G = nx.random_regular_graph(d, len(columnChannels[id]))
|
||||||
if not nx.is_connected(G):
|
if not nx.is_connected(G):
|
||||||
self.logger.error("graph not connected for column %d !" % id, extra=self.format)
|
self.logger.error("Graph not connected for column %d !" % id, extra=self.format)
|
||||||
for u, v in G.edges:
|
for u, v in G.edges:
|
||||||
val1=columnChannels[id][u]
|
val1=columnChannels[id][u]
|
||||||
val2=columnChannels[id][v]
|
val2=columnChannels[id][v]
|
||||||
|
@ -73,15 +76,25 @@ class Simulator:
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
|
||||||
def resetFailureRate(self, failureRate):
|
def resetFailureRate(self, failureRate):
|
||||||
self.failureRate = failureRate
|
self.config.failureRate = failureRate
|
||||||
|
for val in self.validators:
|
||||||
|
val.config.failureRate = failureRate
|
||||||
|
|
||||||
|
def resetChi(self, chi):
|
||||||
|
self.config.chi = chi
|
||||||
|
for val in self.validators:
|
||||||
|
val.config.chi = chi
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.glob.checkRowsColumns(self.validators)
|
self.glob.checkRowsColumns(self.validators)
|
||||||
self.validators[self.proposerID].broadcastBlock()
|
self.validators[self.proposerID].broadcastBlock()
|
||||||
arrived, expected = self.glob.checkStatus(self.validators)
|
arrived, expected = self.glob.checkStatus(self.validators)
|
||||||
missingSamples = expected - arrived
|
missingSamples = expected - arrived
|
||||||
|
missingVector = []
|
||||||
steps = 0
|
steps = 0
|
||||||
while(missingSamples > 0):
|
while(missingSamples > 0):
|
||||||
|
missingVector.append(missingSamples)
|
||||||
oldMissingSamples = missingSamples
|
oldMissingSamples = missingSamples
|
||||||
for i in range(1,self.config.numberValidators):
|
for i in range(1,self.config.numberValidators):
|
||||||
self.validators[i].receiveRowsColumns()
|
self.validators[i].receiveRowsColumns()
|
||||||
|
@ -96,7 +109,7 @@ class Simulator:
|
||||||
arrived, expected = self.glob.checkStatus(self.validators)
|
arrived, expected = self.glob.checkStatus(self.validators)
|
||||||
missingSamples = expected - arrived
|
missingSamples = expected - arrived
|
||||||
missingRate = missingSamples*100/expected
|
missingRate = missingSamples*100/expected
|
||||||
self.logger.info("step %d, missing %d of %d (%0.02f %%)" % (steps, missingSamples, expected, missingRate), extra=self.format)
|
self.logger.debug("step %d, missing %d of %d (%0.02f %%)" % (steps, missingSamples, expected, missingRate), extra=self.format)
|
||||||
if missingSamples == oldMissingSamples:
|
if missingSamples == oldMissingSamples:
|
||||||
break
|
break
|
||||||
elif missingSamples == 0:
|
elif missingSamples == 0:
|
||||||
|
@ -104,10 +117,13 @@ class Simulator:
|
||||||
else:
|
else:
|
||||||
steps += 1
|
steps += 1
|
||||||
|
|
||||||
|
self.result.addMissing(missingVector)
|
||||||
if missingSamples == 0:
|
if missingSamples == 0:
|
||||||
self.logger.debug("The entire block is available at step %d, with failure rate %d !" % (steps, self.failureRate), extra=self.format)
|
self.result.blockAvailable = 1
|
||||||
return 0
|
self.logger.debug("The entire block is available at step %d, with failure rate %d !" % (steps, self.config.failureRate), extra=self.format)
|
||||||
|
return self.result
|
||||||
else:
|
else:
|
||||||
self.logger.debug("The block cannot be recovered, failure rate %d!" % self.failureRate, extra=self.format)
|
self.result.blockAvailable = 0
|
||||||
return 1
|
self.logger.debug("The block cannot be recovered, failure rate %d!" % self.config.failureRate, extra=self.format)
|
||||||
|
return self.result
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ class Validator:
|
||||||
self.block.data[i] = 0
|
self.block.data[i] = 0
|
||||||
nbFailures = self.block.data.count(0)
|
nbFailures = self.block.data.count(0)
|
||||||
measuredFailureRate = nbFailures * 100 / (self.config.blockSize * self.config.blockSize)
|
measuredFailureRate = nbFailures * 100 / (self.config.blockSize * self.config.blockSize)
|
||||||
self.logger.info("Number of failures: %d (%0.02f %%)", nbFailures, measuredFailureRate, extra=self.format)
|
self.logger.debug("Number of failures: %d (%0.02f %%)", nbFailures, measuredFailureRate, extra=self.format)
|
||||||
#broadcasted.print()
|
#broadcasted.print()
|
||||||
for id in range(self.config.blockSize):
|
for id in range(self.config.blockSize):
|
||||||
self.sendColumn(id)
|
self.sendColumn(id)
|
||||||
|
|
30
study.py
30
study.py
|
@ -5,30 +5,34 @@ from DAS import *
|
||||||
|
|
||||||
|
|
||||||
def study():
|
def study():
|
||||||
config = Configuration(64, 20, 10, 256, 8, 0, 0)
|
config = Configuration(0, 64, 256, 0, 100, 20, 8, 16, 4, 0, 10, 1)
|
||||||
sim = Simulator(config)
|
sim = Simulator(config)
|
||||||
sim.initLogger()
|
sim.initLogger()
|
||||||
frRange = []
|
frRange = []
|
||||||
|
results = []
|
||||||
resultRange = []
|
resultRange = []
|
||||||
simCnt = 0
|
simCnt = 0
|
||||||
sim.logger.info("Starting simulations:", extra=sim.format)
|
sim.logger.info("Starting simulations:", extra=sim.format)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
for fr in range(0, 100, config.failureRateStep):
|
for fr in range(config.failureRateStart, config.failureRateStop+1, config.failureRateStep):
|
||||||
if fr % 10 == 0:
|
|
||||||
sim.logger.info("Failure rate %d %% ..." % fr, extra=sim.format)
|
|
||||||
sim.resetFailureRate(fr)
|
sim.resetFailureRate(fr)
|
||||||
result = 0
|
for chi in range(config.chiStart, config.chiStop+1, config.chiStep):
|
||||||
for i in range(config.maxTries):
|
sim.resetChi(chi)
|
||||||
sim.initValidators()
|
blockAvailable = 0
|
||||||
sim.initNetwork()
|
for run in range(config.runStart, config.runStop, config.runStep):
|
||||||
result += sim.run()
|
sim.logger.info("FR: %d %%, Chi: %d %%, Run: %d ..." % (fr, chi, run), extra=sim.format)
|
||||||
simCnt += 1
|
sim.initValidators()
|
||||||
|
sim.initNetwork()
|
||||||
|
result = sim.run()
|
||||||
|
blockAvailable += result.blockAvailable
|
||||||
|
results.append(result)
|
||||||
|
simCnt += 1
|
||||||
frRange.append(fr)
|
frRange.append(fr)
|
||||||
resultRange.append((config.maxTries-result)*100/config.maxTries)
|
resultRange.append((blockAvailable)*100/config.runStop)
|
||||||
end = time.time()
|
end = time.time()
|
||||||
sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format)
|
sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format)
|
||||||
for i in range(len(frRange)):
|
#for i in range(len(frRange)):
|
||||||
sim.logger.info("For failure rate of %d we got %d %% success rate in DAS!" % (frRange[i], resultRange[i]), extra=sim.format)
|
# sim.logger.info("For failure rate of %d we got %d %% success rate in DAS!" % (frRange[i], resultRange[i]), extra=sim.format)
|
||||||
|
|
||||||
|
|
||||||
study()
|
study()
|
||||||
|
|
Loading…
Reference in New Issue