77from log_config import *
88from typing import Tuple
99
10+ def get_duration_errors (trace_function , proxy_function ) -> float :
11+ """
12+ Returns a float value on how close the trace function is to the proxy function. Lower the value, better the correlation.
13+ Euclidean distance between only duration is considered for EcoFaaS functions.
14+
15+ Parameters:
16+ - `trace_function` (dict): Dictionary containing information regarding trace function
17+ - `proxy_function` (dict): Dictionary containing information regarding proxy function
18+
19+ Returns:
20+ - `float`: closeness value
21+ """
22+
23+ try :
24+ trace_duration = trace_function ["duration" ]["75-percentile" ]
25+ proxy_duration = proxy_function ["duration" ]["75-percentile" ]
26+ except KeyError as e :
27+ log .warning (f"Correlation cannot be found. Error: { e } " )
28+ return math .inf
29+
30+ # NOTE: Better Error mechanisms can be considered to improve the correlation
31+ # Currently only the 75%tile memory and duration are considered.
32+ # Euclidean distance between normalized memory and duration is considered
33+ try :
34+ if trace_duration == 0 : trace_duration += 0.01
35+ diff_duration = (math .log (trace_duration ) - math .log (proxy_duration ))
36+ error = diff_duration
37+ return error
38+ except ValueError as e :
39+ log .warning (f"Correlation cannot be found. Error: { e } " )
40+ return math .inf
41+
42+
1043def get_error (trace_function , proxy_function ) -> float :
1144 """
1245 Returns a float value on how close the trace function is to the proxy function. Lower the value, better the correlation.
@@ -45,7 +78,7 @@ def get_error(trace_function, proxy_function) -> float:
4578
4679
4780def get_proxy_function_using_linear_sum_assignment (
48- trace_functions : dict , proxy_functions : dict
81+ trace_functions : dict , proxy_functions : dict , mode : str
4982) -> Tuple [dict , int ]:
5083 """
5184 Obtains the one-to-one mapped proxy function for every trace function
@@ -83,7 +116,10 @@ def get_proxy_function_using_linear_sum_assignment(
83116 # Time complexity : O(n^3) where n is the largest of number of rows/columns
84117 for i in range (m ):
85118 for j in range (n ):
86- error_matrix [i , j ] = get_error (trace_list [i ], proxy_list [j ])
119+ if mode != "EcoFaaS" :
120+ error_matrix [i , j ] = get_error (trace_list [i ], proxy_list [j ])
121+ else :
122+ error_matrix [i , j ] = get_duration_errors (trace_list [i ], proxy_list [i ])
87123
88124 # Do the linear sum assignment problem
89125 row_indices , col_indices = sp .linear_sum_assignment (error_matrix )
@@ -104,9 +140,12 @@ def get_proxy_function_using_linear_sum_assignment(
104140 proxy = pf
105141 break
106142 trace_functions [trace ]["proxy-function" ] = proxy
107- trace_functions [trace ]["proxy-correlation" ] = get_error (
108- trace_functions [trace ], proxy_functions [proxy ]
109- )
143+ if mode == "EcoFaaS" :
144+ trace_functions [trace ]["proxy-correlation" ] = get_duration_errors (trace_functions [trace ], proxy_functions [proxy ])
145+ else :
146+ trace_functions [trace ]["proxy-correlation" ] = get_error (
147+ trace_functions [trace ], proxy_functions [proxy ]
148+ )
110149 log .debug (
111150 f"Found proxy function for { trace } : { trace_functions [trace ]['proxy-function' ]} with correlation: { trace_functions [trace ]['proxy-correlation' ]} "
112151 )
@@ -132,7 +171,7 @@ def get_proxy_function_using_linear_sum_assignment(
132171
133172
134173def get_closest_proxy_function (
135- trace_functions : dict , proxy_functions : dict
174+ trace_functions : dict , proxy_functions : dict , mode : str
136175) -> Tuple [dict , int ]:
137176 """
138177 Obtains the closest proxy function for every trace function
@@ -156,7 +195,10 @@ def get_closest_proxy_function(
156195 min_error = math .inf
157196 min_error_index = - 1
158197 for i in range (0 , len (proxy_list )):
159- error = get_error (trace_functions [function_name ], proxy_list [i ])
198+ if mode == "EcoFaaS" :
199+ error = get_duration_errors (trace_functions [function_name ], proxy_list [i ])
200+ else :
201+ error = get_error (trace_functions [function_name ], proxy_list [i ])
160202 if error < min_error :
161203 min_error = error
162204 min_error_index = i
@@ -168,9 +210,12 @@ def get_closest_proxy_function(
168210 trace_functions [function_name ]["proxy-function" ] = proxy_list [
169211 min_error_index
170212 ]["name" ]
171- trace_functions [function_name ]["proxy-correlation" ] = get_error (
172- trace_functions [function_name ], proxy_list [min_error_index ]
173- )
213+ if mode == "EcoFaaS" :
214+ trace_functions [function_name ] = get_duration_errors (trace_functions [function_name ], proxy_list [min_error_index ])
215+ else :
216+ trace_functions [function_name ]["proxy-correlation" ] = get_error (
217+ trace_functions [function_name ], proxy_list [min_error_index ]
218+ )
174219 log .debug (
175220 f"Found proxy function for { function_name } : { trace_functions [function_name ]['proxy-function' ]} with correlation: { trace_functions [function_name ]['proxy-correlation' ]} "
176221 )
@@ -186,7 +231,7 @@ def get_closest_proxy_function(
186231
187232
188233def get_proxy_function (
189- trace_functions : dict , proxy_functions : dict , unique_assignment : bool
234+ trace_functions : dict , proxy_functions : dict , unique_assignment : bool , mode : str
190235) -> Tuple [dict , int ]:
191236 """
192237 Obtains the closest proxy function for every trace function
@@ -213,7 +258,7 @@ def get_proxy_function(
213258 f"Getting One-To-One mapping between trace function and proxy function using Linear-Sum-Assignment"
214259 )
215260 trace_functions , err = get_proxy_function_using_linear_sum_assignment (
216- trace_functions = trace_functions , proxy_functions = proxy_functions
261+ trace_functions = trace_functions , proxy_functions = proxy_functions , mode = mode
217262 )
218263 if err == - 1 :
219264 log .error (
@@ -223,7 +268,7 @@ def get_proxy_function(
223268 f"Getting closest proxy function for every trace function. Note: Mapping may not be unique"
224269 )
225270 trace_functions , err = get_closest_proxy_function (
226- trace_functions = trace_functions , proxy_functions = proxy_functions
271+ trace_functions = trace_functions , proxy_functions = proxy_functions , mode = mode
227272 )
228273
229274 elif (unique_assignment ) and (len (trace_functions ) > len (proxy_functions )):
@@ -234,15 +279,15 @@ def get_proxy_function(
234279 f"Getting closest proxy function for every trace function. Note: Mapping may not be unique"
235280 )
236281 trace_functions , err = get_closest_proxy_function (
237- trace_functions = trace_functions , proxy_functions = proxy_functions
282+ trace_functions = trace_functions , proxy_functions = proxy_functions , mode = mode
238283 )
239284
240285 else :
241286 log .info (
242287 f"Getting closest proxy function for every trace function. Note: Mapping may not be unique"
243288 )
244289 trace_functions , err = get_closest_proxy_function (
245- trace_functions = trace_functions , proxy_functions = proxy_functions
290+ trace_functions = trace_functions , proxy_functions = proxy_functions , mode = mode
246291 )
247292
248293 if err == - 1 :
0 commit comments