-
Notifications
You must be signed in to change notification settings - Fork 1
/
faas_runner.py
executable file
·228 lines (191 loc) · 7.1 KB
/
faas_runner.py
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python3
#
# FaaS Runner is an interface to run FaaS experiments. Feed in function.json files and experiment.json files
# to determine how an experiment will execute and how the report will be generated.
#
# @author Robert Cordingly
#
import ast
import cmd
import datetime
import json
import os
import subprocess
import sys
import time
from decimal import Decimal
from enum import Enum
import copy
sys.path.append('./tools')
from report_generator import report
from experiment_orchestrator import publish, run_experiment
# Default function options:
defaultFunction = {
'function': 'HELLOWORLD',
'platform': 'AWS Lambda',
'source': '.',
'endpoint': ''
}
# Default experiment options:
defaultExperiment = {
'callWithCLI': True,
'callAsync': False,
'memorySettings': [],
'parentPayload': {},
'payloads': [{}],
'payloadFolder': '',
'shufflePayloads': False,
'runs': 10,
'threads': 10,
'iterations': 1,
'sleepTime': 0,
'randomSeed': 42,
'outputGroups': [],
'outputRawOfGroup': [],
'showAsList': [],
'showAsSum': [],
'ignoreFromAll': [],
'ignoreFromGroups': [],
'ignoreByGroup': [],
'invalidators': {},
'removeDuplicateContainers': False,
'overlapFilter': "",
'openCSV': True,
'combineSheets': False,
'warmupBuffer': 0,
'experimentName': "DEFAULT-EXP",
'passPayloads': False,
'transitions': {},
'simpleOutput': True
}
# Modes for parsing parameters.
class Mode(Enum):
FUNC = 1
EXP = 2
OUT = 3
NONE = 4
OVERRIDE = 5
#
# Use command line arguments to select function and experiments.
#
if (len(sys.argv) > 1):
print("\n-----------------------------------------------------------------")
print("LOADING EXPERIMENTS AND APPLYING OVERRIDES.... (faas_runner.py)")
print("-----------------------------------------------------------------\n")
mode = Mode.NONE
outDir = "./history"
overrides = {}
functionList = []
expList = []
# Parse arguments
for arg in sys.argv:
if (arg == "-f"):
mode = Mode.FUNC
elif (arg == "-e"):
mode = Mode.EXP
elif (arg == "-o"):
mode = Mode.OUT
elif ('--' in arg):
mode = Mode.OVERRIDE
overrideAttribute = arg[2:]
overrides[overrideAttribute] = ""
else:
if mode == Mode.FUNC:
functionList.append(arg)
elif mode == Mode.EXP:
expList.append(arg)
elif mode == Mode.OUT:
outDir = arg
elif mode == Mode.OVERRIDE:
overrides[overrideAttribute] += arg
print("\nOverrides: " + str(overrides))
#if (len(functionList) > 0 and len(expList) > 0 or True):
if (not os.path.isdir(outDir)):
os.mkdir(outDir)
loadedFunctions = []
loadedExperiments = []
# Load in place the function files as dictionaries.
for index, function in enumerate(functionList):
nextFunction = json.load(open(function))
nextFunction['sourceFile'] = function
functionList[index] = nextFunction
# Load in place the experiments files as dictionaries.
for index, experiment in enumerate(expList):
nextExperiment = json.load(open(experiment))
nextExperiment['sourceFile'] = experiment
nextExperiment['experimentName'] = os.path.basename(experiment).replace(".json", "")
expList[index] = nextExperiment
# Add in default function in the event none are supplied. If parameters have indices add more default functions.
if (len(functionList) == 0):
maxFunctions = 1
for key in overrides:
if '[' in key and ']' in key:
subIndex = int(key[key.find('[')+1:key.find(']')]) + 1
if subIndex > maxFunctions: maxFunctions = subIndex
for i in range(0, maxFunctions):
functionList.append(defaultFunction)
# Add in default experiment in the event none are supplied. If parameters have indices add more default experiments.
if (len(expList) == 0):
maxExperiments = 1
for key in overrides:
if '[' in key and ']' in key:
subIndex = int(key[key.find('[')+1:key.find(']')]) + 1
if subIndex > maxExperiments: maxExperiments = subIndex
for i in range(0, maxExperiments):
expList.append(defaultExperiment)
# Apply inheritance to function objects.
for index, function in enumerate(functionList):
function = copy.deepcopy(function)
# Set default options if needed.
for key in defaultFunction:
if key not in function:
function[key] = defaultFunction[key]
print("NOTE: " + str(key) + " missing in function file! Using default option of "
+ str(defaultFunction[key]))
# Add in overrides for function.
for key in overrides:
modifiedKey = key
# If the key has an index skip it if index does not match function index.
if '[' in key and ']' in key:
subIndex = int(key[key.find('[')+1:key.find(']')])
if index != subIndex: continue
modifiedKey = key[:key.find('[')]
function[modifiedKey] = overrides[key]
print("\nLoaded function: " + str(function))
loadedFunctions.append(function)
print("\n---Loaded function list: " + str(loadedFunctions))
# Load in experiment files
for index, experiment in enumerate(expList):
experiment = copy.deepcopy(experiment)
# Set default options if needed.
for key in defaultExperiment:
if key not in experiment:
experiment[key] = defaultExperiment[key]
print("NOTE: " + str(key) + " missing in experiment file! Using default option of "
+ str(defaultExperiment[key]))
# Add in overrides for experiments.
for key in overrides:
modifiedKey = key
# If the key has an index skip it if index does not match experiment index.
if '[' in key and ']' in key:
subIndex = int(key[key.find('[')+1:key.find(']')])
if index != subIndex: continue
modifiedKey = key[:key.find('[')]
value = overrides[key]
try:
# Try to load as an integer
experiment[modifiedKey] = int(overrides[key])
except ValueError:
try:
# Try to load a JSON
experiment[modifiedKey] = json.loads(overrides[key])
except ValueError as e:
# Give up and load a string
experiment[modifiedKey] = overrides[key]
print("\nLoaded experiment: " + str(experiment))
loadedExperiments.append(experiment)
print("\n---Loaded experiment list: " + str(loadedExperiments))
run_experiment(loadedFunctions, loadedExperiments, outDir)
else:
print("Please supply parameteres! Usage:\n" +
"./faas_runner.py -f {PATH TO FUNCTION JSON} -e {PATH TO EXPERIMENT JSON} -o {OPTIONAL: PATH FOR OUTPUT}")