-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
156 lines (133 loc) · 6.06 KB
/
main.py
File metadata and controls
156 lines (133 loc) · 6.06 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
import sys
import math
import numpy as np
import yaml
import faas
import conf
import stateful
from arrivals import PoissonArrivalProcess, TraceArrivalProcess, MAPArrivalProcess
from numpy.random import SeedSequence, default_rng
from simulation import Simulation
from infrastructure import *
def read_spec_file (spec_file_name, infra, config):
peer_exposed_memory_fraction = config.getfloat(conf.SEC_SIM, conf.EDGE_EXPOSED_FRACTION, fallback=0.5)
with open(spec_file_name, "r") as stream:
spec = yaml.safe_load(stream)
classname2class={}
classes = []
for c in spec["classes"]:
classname = c["name"]
arrival_weight = c.get("arrival_weight", 1.0)
utility = c.get("utility", 1.0)
penalty = c.get("penalty", 0.0)
if penalty > 0.0:
print("[WARNING] Using the deprecated 'penalty' attribute")
deadline_penalty = penalty
drop_penalty = 0.0
else:
deadline_penalty = c.get("deadline_penalty", 0.0)
drop_penalty = c.get("drop_penalty", 0.0)
deadline = c.get("max_resp_time", 1.0)
newclass = faas.QoSClass(classname, deadline, arrival_weight, utility=utility, deadline_penalty=deadline_penalty, drop_penalty=drop_penalty)
classes.append(newclass)
classname2class[classname]=newclass
node_names = {}
nodes = spec["nodes"]
for n in nodes:
node_name = n["name"]
reg_name = n["region"]
reg = infra.get_region(reg_name)
memory = n["memory"] if "memory" in n else 1024
speedup = n["speedup"] if "speedup" in n else 1.0
cost = n["cost"] if "cost" in n else 0.0
custom_policy = n["policy"] if "policy" in n else None
node = faas.Node(node_name, memory, speedup, reg, cost=cost,
custom_sched_policy=custom_policy,
peer_exposed_memory_fraction=peer_exposed_memory_fraction)
node_names[node_name] = node
infra.add_node(node, reg)
functions = []
function_names = {}
for f in spec["functions"]:
fname = f["name"]
memory = f["memory"] if "memory" in f else 128
duration_mean = f["duration_mean"] if "duration_mean" in f else 1.0
duration_scv = f["duration_scv"] if "duration_scv" in f else 1.0
init_mean = f["init_mean"] if "init_mean" in f else 0.500
input_mean = f["input_mean"] if "input_mean" in f else 1024
keys_spec = f["keys"] if "keys" in f else []
max_data_access_time = f["max_data_access_time"] if "max_data_access_time" in f else None
keys=[]
for ks in keys_spec:
key = ks["key"]
p = float(ks.get("probability", "1.0"))
assert(p <= 1.0)
assert(p >= 0.0)
keys.append((key, p))
fun = faas.Function(fname, memory, serviceMean=duration_mean, serviceSCV=duration_scv, initMean=init_mean, inputSizeMean=input_mean, accessed_keys=keys, max_data_access_time=max_data_access_time)
function_names[fname] = fun
functions.append(fun)
node2arrivals = {}
for f in spec["arrivals"]:
node = node_names[f["node"]]
fun = function_names[f["function"]]
if not "classes" in f:
invoking_classes = classes
else:
invoking_classes = [classname2class[qcname] for qcname in f["classes"]]
if "trace" in f:
arv = TraceArrivalProcess(fun, invoking_classes, f["trace"])
elif "rate" in f:
dynamic_rate_coeff = float(f["dynamic_coeff"]) if "dynamic_coeff" in f else 0.0
arv = PoissonArrivalProcess(fun, invoking_classes, float(f["rate"]), dynamic_rate_coeff=dynamic_rate_coeff)
elif "map" in f:
# map: 1;2;3;4;...
matrix_entries = f["map"].split(";")
n = int(math.sqrt(len(matrix_entries)/2))
assert(n*n*2 == len(matrix_entries))
D0str = ""
k=0
for i in range(n):
for j in range(n):
D0str += f"{matrix_entries[k]} "
k+=1
D0str += ";"
D1str = ""
for i in range(n):
for j in range(n):
D1str += f"{matrix_entries[k]} "
k+=1
D1str += ";"
D0 = np.matrix(D0str[:-1]) # strip last semicolon
D1 = np.matrix(D1str[:-1])
arv = MAPArrivalProcess(fun, invoking_classes, D0=D0, D1=D1)
if not node in node2arrivals:
node2arrivals[node] = []
node2arrivals[node].append(arv)
return classes, functions, node2arrivals
def init_simulation (config):
seed = config.getint(conf.SEC_SIM, conf.SEED, fallback=1)
seed_sequence = SeedSequence(seed)
# Regions
reg_cloud = Region("cloud")
reg_edge = Region("edge", reg_cloud)
regions = [reg_edge, reg_cloud]
# Latency
latencies = {(reg_edge,reg_cloud): 0.100, (reg_edge,reg_edge): 0.005}
bandwidth_mbps = {(reg_edge,reg_edge): 100.0, (reg_cloud,reg_cloud): 1000.0,\
(reg_edge,reg_cloud): 10.0}
# Infrastructure
infra = Infrastructure(regions, latencies, bandwidth_mbps)
# Read spec file
spec_file_name = config.get(conf.SEC_SIM, conf.SPEC_FILE, fallback=None)
classes, functions, node2arrivals = read_spec_file (spec_file_name, infra, config)
sim = Simulation(config, seed_sequence, infra, functions, classes, node2arrivals)
return sim
def main():
DEFAULT_CONFIG_FILE = "config.ini"
config_file = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_CONFIG_FILE
config = conf.parse_config_file(config_file)
simulation = init_simulation(config)
final_stats = simulation.run()
if __name__ == "__main__":
main()