diff --git a/sebs/cache.py b/sebs/cache.py index ed5096e6..86eff067 100644 --- a/sebs/cache.py +++ b/sebs/cache.py @@ -158,6 +158,7 @@ def update_storage(self, deployment: str, benchmark: str, config: dict): with self._lock: with open(os.path.join(benchmark_dir, "config.json"), "r") as fp: cached_config = json.load(fp) + cached_config[deployment] = {} cached_config[deployment]["storage"] = config with open(os.path.join(benchmark_dir, "config.json"), "w") as fp: json.dump(cached_config, fp, indent=2) diff --git a/sebs/experiments/perf_cost.py b/sebs/experiments/perf_cost.py index 36cde660..5372e887 100644 --- a/sebs/experiments/perf_cost.py +++ b/sebs/experiments/perf_cost.py @@ -85,7 +85,6 @@ def run(self): self.run_configuration(settings, settings["repetitions"], suffix=str(memory)) def compute_statistics(self, times: List[float]): - mean, median, std, cv = basic_stats(times) self.logging.info(f"Mean {mean} [ms], median {median} [ms], std {std}, CV {cv}") for alpha in [0.95, 0.99]: @@ -156,7 +155,6 @@ def _run_configuration( self._deployment_client.enforce_cold_start( [self._function], self._benchmark ) - time.sleep(5) results = [] @@ -224,7 +222,6 @@ def _run_configuration( ) def run_configuration(self, settings: dict, repetitions: int, suffix: str = ""): - for experiment_type in settings["experiments"]: if experiment_type == "cold": self._run_configuration( diff --git a/sebs/local/function.py b/sebs/local/function.py index a5eb2406..a918159c 100644 --- a/sebs/local/function.py +++ b/sebs/local/function.py @@ -99,6 +99,7 @@ def deserialize(cached_config: dict) -> "LocalFunction": ) except docker.errors.NotFound: raise RuntimeError(f"Cached container {instance_id} not available anymore!") + # FIXME: clear cache def stop(self): self.logging.info(f"Stopping function container {self._instance_id}") diff --git a/sebs/local/local.py b/sebs/local/local.py index 2d1567b0..e1513727 100644 --- a/sebs/local/local.py +++ b/sebs/local/local.py @@ -103,8 +103,8 @@ def get_storage(self, replace_existing: bool = False) -> PersistentStorage: """ def shutdown(self): - pass - + if hasattr(self, "storage") and self.config.shutdownStorage: + self.storage.stop() """ It would be sufficient to just pack the code and ship it as zip to AWS. However, to have a compatible function implementation across providers, @@ -170,8 +170,10 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc self.name(), code_package.language_name ), } + container = self._docker_client.containers.run( image=container_name, + name=func_name, command=f"/bin/bash /sebs/run_server.sh {self.DEFAULT_PORT}", volumes={code_package.code_location: {"bind": "/function", "mode": "ro"}}, environment=environment, @@ -224,12 +226,13 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc ) return func - """ - FIXME: restart Docker? - """ - def update_function(self, function: Function, code_package: Benchmark): - pass + # kill existing containers + for ctr in self._docker_client.containers.list(): + if ctr.name in function.name: + ctr.kill() + # deploy new containers with updated function + self.create_function(code_package, function.name) """ For local functions, we don't need to do anything for a cached function. @@ -251,7 +254,8 @@ def create_trigger(self, func: Function, trigger_type: Trigger.TriggerType) -> T return trigger def cached_function(self, function: Function): - pass + for trigger in function.triggers(Trigger.TriggerType.LIBRARY): + trigger.logging_handlers = self.logging_handlers def update_function_configuration(self, function: Function, code_package: Benchmark): self.logging.error("Updating function configuration of local deployment is not supported") @@ -268,7 +272,10 @@ def download_metrics( pass def enforce_cold_start(self, functions: List[Function], code_package: Benchmark): - raise NotImplementedError() + fn_names = [fn.name for fn in functions] + for ctr in self._docker_client.containers.list(): + if ctr.name in fn_names: + ctr.kill() @staticmethod def default_function_name(code_package: Benchmark) -> str: