Skip to content

Commit 1fb86c8

Browse files
committed
reformatting
1 parent 476a2a3 commit 1fb86c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+609
-566
lines changed

Distribution/HDFS.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import sys
2+
23
sys.path.append("..")
34

45
import random, math
56
from Topology.FatTree import *
67

8+
79
class AllocChunks:
810
"""
911
This class builds the chunks distribution in HDFS.
1012
"""
13+
1114
def __init__(self, M, d, n, topo):
1215
"""
1316
M: the rank range of items, it indicates the number of distinct chunks in HDFS
@@ -102,5 +105,3 @@ def AllocatesNow(self):
102105

103106
def __del__(self):
104107
pass
105-
106-

Distribution/PowerLawOnHDFS.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
2-
31
import sys
2+
43
sys.path.append("..")
54

6-
import random, getopt
5+
import getopt
76
from HDFS import *
87
from RandomGenerator.PowerLaw import *
98
from RandomGenerator.Poisson import *
@@ -106,6 +105,7 @@ def AllocateFlows(topo, hdfs, pl, ps):
106105

107106
f.close()
108107

108+
109109
def main():
110110
"""
111111
Now we just provide allocation function for power-law distribution in traditional HDFS distribution.
@@ -124,5 +124,6 @@ def main():
124124
# allocates flows
125125
AllocateFlows(topo, hdfs, pl, ps)
126126

127+
127128
if __name__ == "__main__":
128129
main()

Distribution/WeightedChoice.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import random
44

5+
56
def weighted_choice(choices):
67
total = sum([choices[c] for c in choices])
78
r = random.uniform(0, total)
@@ -12,10 +13,11 @@ def weighted_choice(choices):
1213
upto += choices[c]
1314
assert False, "Shouldn't get here"
1415

16+
1517
# Usage example
16-
if __name__=="__main__":
18+
if __name__ == "__main__":
1719
choice = ['a', 'b', 'c', 'd']
1820
weight = [1, 2, 3, 4]
1921
css = dict(zip(choice, weight))
2022
for i in range(10):
21-
print weighted_choice(css)
23+
print weighted_choice(css)

Distribution/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

LoadBalance/Hedera_SpineLeaf.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
class Hedera_SpineLeaf(object):
52
def __init__(self):
63
pass

LoadBalance/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

RandomGenerator/Poisson.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import random
2+
import math
13

24

3-
import random, math
4-
55
class PoissonRand:
66
"""
77
This is used to generate poisson numbers.
@@ -12,6 +12,7 @@ class PoissonRand:
1212
Thus, we random generate a P in (0, 1) and calculate the delta_t by the equation above.
1313
Note that if P is extremely small, for example, P = 0, that leads to an infinite delta_t, therefore, we needs to set a bound.
1414
"""
15+
1516
def __init__(self, mean, bound):
1617
self.mean = mean
1718
self.bound = bound

RandomGenerator/PowerLaw.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
class PowerLaw:
32
"""
43
This class is used to generate power-law distribution.
54
"""
6-
def __init__(self, alpha=1.0, totalNums = 1000, rank=100):
5+
6+
def __init__(self, alpha=1.0, totalNums=1000, rank=100):
77
self.alpha = alpha
88
self.N = totalNums
99
self.rankRange = rank
@@ -40,4 +40,3 @@ def GetDistribution(self):
4040
else:
4141
break
4242
return dist
43-

RandomGenerator/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

Routing/ECMP_FatTree.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
2-
31
import sys
2+
43
sys.path.append("..")
54

65
from Topology.FatTree import *
76
from Src.Routing import *
87

9-
import gc
108

119
class ECMP(Routing):
1210
"""
1311
This routing approach is specific for fat-tree topology
1412
"""
13+
1514
def __init__(self, topo):
1615
Routing.__init__(self, topo)
1716
self.K = topo.K
@@ -33,7 +32,7 @@ def CalculateAllPath(self):
3332
Note that besides serverId, switch Id is required to convert into node id
3433
"""
3534
for srcId in range(1, self.numOfServers + 1):
36-
#gc.collect()
35+
# gc.collect()
3736
for dstId in range(1, self.numOfServers + 1):
3837
self.CalculatePath(srcId=srcId, dstId=dstId)
3938

Routing/ECMP_SpineLeaf.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
2-
31
import sys
2+
43
sys.path.append("..")
54

6-
from Topology.SpineLeaf import *
75
from Src.Routing import *
86
from random import choice
9-
import gc
7+
108

119
class ECMP(Routing):
1210
"""
1311
This routing approach is specific for spine-leaf topology
1412
"""
13+
1514
def __init__(self, topo):
1615
Routing.__init__(self, topo)
1716
self.numOfServers = topo.numOfServers
@@ -31,7 +30,7 @@ def CalculateAllPath(self):
3130
For spine-leaf, choosing a path is essentially choosing a spine to traverse
3231
"""
3332
for srcId in range(self.numOfServers):
34-
#gc.collect()
33+
# gc.collect()
3534
for dstId in range(self.numOfServers):
3635
self.CalculatePath(srcId=srcId, dstId=dstId)
3736

@@ -49,7 +48,8 @@ def CalculatePath(self, srcId, dstId, flow):
4948
# src-dst must traverse core
5049
else:
5150
# prick random core
52-
rcore = choice(range(self.numOfServers + self.numOfToRs, self.numOfServers + self.numOfToRs + self.numOfCores))
51+
rcore = choice(
52+
range(self.numOfServers + self.numOfToRs, self.numOfServers + self.numOfToRs + self.numOfCores))
5353
self.pathList[srcId, dstId] = [srcId, srcToRId, rcore, dstToRId, dstId]
5454

5555
def __del__(self):

Routing/FlowLB_SpineLeaf.py

+41-44
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
1-
2-
31
import sys
2+
43
sys.path.append("..")
54

6-
from Topology.SpineLeaf import *
75
from Src.Routing import *
8-
from random import choice
9-
import gc
6+
107

118
class FlowLB(Routing):
129
"""
1310
This routing approach is specific for spine-leaf topology
1411
"""
12+
1513
def __init__(self, topo):
1614
Routing.__init__(self, topo)
17-
#self.numOfServers = topo.numOfServers
18-
#self.serverPerRack = topo.serverPerRack
19-
#self.numOfToRs = topo.numOfToRs
20-
#self.numOfCores = topo.numOfCores
21-
self.topo=topo
15+
# self.numOfServers = topo.numOfServers
16+
# self.serverPerRack = topo.serverPerRack
17+
# self.numOfToRs = topo.numOfToRs
18+
# self.numOfCores = topo.numOfCores
19+
self.topo = topo
2220

2321
def BuildAllPath(self):
2422
self.CalculateAllPath()
2523

2624
def BuildPath(self, srcId, dstId, flow, flows):
2725
self.CalculatePath(srcId, dstId, flow, flows)
2826

29-
# def CalculateAllPath(self):
30-
# """
31-
# This function calculate path between each pair of servers by choosing a core switch with least traversing flows. For spine-leaf, choosing a path is essentially choosing a spine to travers
32-
# """
33-
# for srcId in range(1, self.numOfServers + 1):
34-
# #gc.collect()
35-
# for dstId in range(1, self.numOfServers + 1):
36-
# self.CalculatePath(srcId=srcId, dstId=dstId)
27+
# def CalculateAllPath(self):
28+
# """
29+
# This function calculate path between each pair of servers by choosing a core switch with least traversing flows. For spine-leaf, choosing a path is essentially choosing a spine to travers
30+
# """
31+
# for srcId in range(1, self.numOfServers + 1):
32+
# #gc.collect()
33+
# for dstId in range(1, self.numOfServers + 1):
34+
# self.CalculatePath(srcId=srcId, dstId=dstId)
3735

38-
def GetCoreLeastFlow(self, flows):
39-
cores = []
40-
for i in range(self.topo.numOfCores):
41-
cores.append(self.topo.GetCoreNode(i))
42-
# print "cores {}".format(cores)
43-
dc ={}
36+
def GetCoreLeastFlow(self, flows):
37+
cores = []
38+
for i in range(self.topo.numOfCores):
39+
cores.append(self.topo.GetCoreNode(i))
40+
# print "cores {}".format(cores)
41+
dc = {}
4442
for c in cores:
4543
fsize = 0.0
4644
for flowId in c.flowIds:
4745
fsize += flows[flowId].remainSize
4846
dc[c] = fsize
49-
#for key in dc.keys():
50-
#print "key= ",key.nodeId," dc[key]= ",dc[key]," "
51-
#print "min of dc ",min(dc, key=dc.get).nodeId
52-
return min(dc, key=dc.get)
53-
54-
def GetCoreLeastQ(self):
55-
cores = []
56-
for i in range(self.topo.numOfCores):
57-
cores.append(self.topo.GetCoreNode(i))
58-
# print "cores {}".format(cores)
59-
dc = dict([(c, len(c.qvalue)) for c in cores])
60-
return min(dc, key=dc.get)
47+
# for key in dc.keys():
48+
# print "key= ",key.nodeId," dc[key]= ",dc[key]," "
49+
# print "min of dc ",min(dc, key=dc.get).nodeId
50+
return min(dc, key=dc.get)
51+
52+
def GetCoreLeastQ(self):
53+
cores = []
54+
for i in range(self.topo.numOfCores):
55+
cores.append(self.topo.GetCoreNode(i))
56+
# print "cores {}".format(cores)
57+
dc = dict([(c, len(c.qvalue)) for c in cores])
58+
return min(dc, key=dc.get)
6159

6260
def CalculatePath(self, srcId, dstId, flow, flows):
6361
# only self id is contained, if destination is self
@@ -70,17 +68,16 @@ def CalculatePath(self, srcId, dstId, flow, flows):
7068
if srcToRId == dstToRId:
7169
self.pathList[srcId, dstId] = [srcId, srcToRId, dstId]
7270
return
73-
# src-dst must traverse core
71+
# src-dst must traverse core
7472
else:
7573
# prick random core
76-
# rcore = choice(range(self.numOfServers+self.numOfToRs+1, self.numOfServers + self.numOfToRs + self.numOfCores + 1))
77-
# if flow.coflowId == 0:
78-
rcore=self.GetCoreLeastFlow(flows)
79-
# else:
80-
# rcore=self.topo.GetCoreNode(flow.coflowId % self.topo.numOfCores)
81-
rcoreId=rcore.nodeId
74+
# rcore = choice(range(self.numOfServers+self.numOfToRs+1, self.numOfServers + self.numOfToRs + self.numOfCores + 1))
75+
# if flow.coflowId == 0:
76+
rcore = self.GetCoreLeastFlow(flows)
77+
# else:
78+
# rcore=self.topo.GetCoreNode(flow.coflowId % self.topo.numOfCores)
79+
rcoreId = rcore.nodeId
8280
self.pathList[srcId, dstId] = [srcId, srcToRId, rcoreId, dstToRId, dstId]
83-
8481

8582
def __del__(self):
8683
pass

0 commit comments

Comments
 (0)