Added extra parameter for deque sizes

This commit is contained in:
Sudipta Basak 2024-03-04 10:58:15 +00:00
parent 977b0b3caa
commit 46481c0370
No known key found for this signature in database
5 changed files with 25 additions and 14 deletions

View File

@ -4,7 +4,7 @@ class Shape:
"""This class represents a set of parameters for a specific simulation."""
def __init__(self, blockSizeR, blockSizeRK, blockSizeC, blockSizeCK,
numberNodes, failureModel, failureRate, class1ratio, chiR, chiC, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run):
numberNodes, failureModel, failureRate, class1ratio, chiR, chiC, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run, sendDqSize, receivedDqSize):
"""Initializes the shape with the parameters passed in argument."""
self.run = run
self.numberNodes = numberNodes
@ -24,6 +24,8 @@ class Shape:
self.bwUplink1 = bwUplink1
self.bwUplink2 = bwUplink2
self.randomSeed = ""
self.sendDqSize = sendDqSize
self.receivedDqSize = receivedDqSize
def __repr__(self):
"""Returns a printable representation of the shape"""
@ -45,6 +47,8 @@ class Shape:
shastr += "-bwup2-"+str(self.bwUplink2)
shastr += "-nd-"+str(self.netDegree)
shastr += "-r-"+str(self.run)
shastr += "-sdq-"+str(self.sendDqSize)
shastr += "-rdq-"+str(self.receivedDqSize)
return shastr
def setSeed(self, seed):

View File

@ -147,8 +147,8 @@ class Simulator:
for u, v in G.edges:
val1=rowChannels[id][u]
val2=rowChannels[id][v]
val1.rowNeighbors[id].update({val2.ID : Neighbor(val2, 0, self.shape.blockSizeR)})
val2.rowNeighbors[id].update({val1.ID : Neighbor(val1, 0, self.shape.blockSizeR)})
val1.rowNeighbors[id].update({val2.ID : Neighbor(val2, 0, self.shape.blockSizeR, self.shape.sendDqSize)})
val2.rowNeighbors[id].update({val1.ID : Neighbor(val1, 0, self.shape.blockSizeR, self.shape.sendDqSize)})
for id in range(self.shape.blockSizeR):
@ -165,8 +165,8 @@ class Simulator:
for u, v in G.edges:
val1=columnChannels[id][u]
val2=columnChannels[id][v]
val1.columnNeighbors[id].update({val2.ID : Neighbor(val2, 1, self.shape.blockSizeC)})
val2.columnNeighbors[id].update({val1.ID : Neighbor(val1, 1, self.shape.blockSizeC)})
val1.columnNeighbors[id].update({val2.ID : Neighbor(val2, 1, self.shape.blockSizeC, self.shape.sendDqSize)})
val2.columnNeighbors[id].update({val1.ID : Neighbor(val1, 1, self.shape.blockSizeC, self.shape.sendDqSize)})
for v in self.validators:
if (self.proposerPublishOnly and v.amIproposer):
@ -174,12 +174,12 @@ class Simulator:
count = min(self.proposerPublishTo, len(rowChannels[id]))
publishTo = random.sample(rowChannels[id], count)
for vi in publishTo:
v.rowNeighbors[id].update({vi.ID : Neighbor(vi, 0, self.shape.blockSizeR)})
v.rowNeighbors[id].update({vi.ID : Neighbor(vi, 0, self.shape.blockSizeR, self.shape.sendDqSize)})
for id in v.columnIDs:
count = min(self.proposerPublishTo, len(columnChannels[id]))
publishTo = random.sample(columnChannels[id], count)
for vi in publishTo:
v.columnNeighbors[id].update({vi.ID : Neighbor(vi, 1, self.shape.blockSizeC)})
v.columnNeighbors[id].update({vi.ID : Neighbor(vi, 1, self.shape.blockSizeC, self.shape.sendDqSize)})
if self.logger.isEnabledFor(logging.DEBUG):
for i in range(0, self.shape.numberNodes):

View File

@ -21,14 +21,14 @@ class Neighbor:
"""It returns the amount of sent and received data."""
return "%d:%d/%d, q:%d" % (self.node.ID, self.sent.count(1), self.received.count(1), len(self.sendQueue))
def __init__(self, v, dim, blockSize):
def __init__(self, v, dim, blockSize, sendDqSize):
"""It initializes the neighbor with the node and sets counters to zero."""
self.node = v
self.dim = dim # 0:row 1:col
self.receiving = zeros(blockSize)
self.received = zeros(blockSize)
self.sent = zeros(blockSize)
self.sendQueue = deque()
self.sendQueue = deque(maxlen=sendDqSize)
class Validator:
@ -51,8 +51,8 @@ class Validator:
self.format = {"entity": "Val "+str(self.ID)}
self.block = Block(self.shape.blockSizeR, self.shape.blockSizeRK, self.shape.blockSizeC, self.shape.blockSizeCK)
self.receivedBlock = Block(self.shape.blockSizeR, self.shape.blockSizeRK, self.shape.blockSizeC, self.shape.blockSizeCK)
self.receivedQueue = deque()
self.sendQueue = deque()
self.receivedQueue = deque(maxlen=self.shape.receivedDqSize)
self.sendQueue = deque(maxlen=self.shape.sendDqSize)
self.amIproposer = amIproposer
self.logger = logger
if self.shape.chiR < 1 and self.shape.chiC < 1:

View File

@ -33,7 +33,11 @@ def runOnce(config, shape, execID):
sim.initLogger()
sim.initValidators()
sim.initNetwork()
tic = time.time()
result = sim.run()
toc = time.time()
timed = f"(send: {shape.sendDqSize}, received: {shape.receivedDqSize}): {toc - tic}"
print(timed)
sim.logger.info("Shape: %s ... Block Available: %d in %d steps" % (str(sim.shape.__dict__), result.blockAvailable, len(result.missingVector)), extra=sim.format)
if config.dumpXML:

View File

@ -102,14 +102,17 @@ diagnostics = False
# True to save git diff and git commit
saveGit = False
# deque sizes => (send deque, received deque)
dequeSizes = [(7, 10), (10, 31), (18, 115), (25, 315), (32, 395), (39, 395)]
def nextShape():
for run, fm, fr, class1ratio, vpn1, vpn2, nn, netDegree, bwUplinkProd, bwUplink1, bwUplink2 in itertools.product(
runs, failureModels, failureRates, class1ratios, validatorsPerNode1, validatorsPerNode2, numberNodes, netDegrees, bwUplinksProd, bwUplinks1, bwUplinks2):
for run, fm, fr, class1ratio, vpn1, vpn2, nn, netDegree, bwUplinkProd, bwUplink1, bwUplink2, (sendDqSize, receivedDqSize) in itertools.product(
runs, failureModels, failureRates, class1ratios, validatorsPerNode1, validatorsPerNode2, numberNodes, netDegrees, bwUplinksProd, bwUplinks1, bwUplinks2, dequeSizes):
# Network Degree has to be an even number
if netDegree % 2 == 0:
blockSizeR = 128
blockSizeC = blockSizeRK = blockSizeCK = 64
chiR = 0
chiC = 4
shape = Shape(blockSizeR, blockSizeRK, blockSizeC, blockSizeCK, nn, fm, fr, class1ratio, chiR, chiC, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run)
shape = Shape(blockSizeR, blockSizeRK, blockSizeC, blockSizeCK, nn, fm, fr, class1ratio, chiR, chiC, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run, sendDqSize, receivedDqSize)
yield shape