diff --git a/lithops/localhost/v1/localhost.py b/lithops/localhost/v1/localhost.py index 5d2cd9cf..28e67c7c 100644 --- a/lithops/localhost/v1/localhost.py +++ b/lithops/localhost/v1/localhost.py @@ -172,6 +172,7 @@ def get_runtime_info(self): return { 'runtime_name': self.config['runtime'], 'runtime_memory': self.config.get('runtime_memory'), + 'runtime_cpu': self.config.get('runtime_cpu'), 'runtime_timeout': self.config.get('runtime_timeout'), 'max_workers': self.config['max_workers'], } @@ -346,9 +347,14 @@ def get_metadata(self): cmd = f'{self.docker_path} run --name lithops_metadata ' cmd += f'--user {self.uid}:{self.gid} ' if self.is_unix_system and not self.is_podman else '' cmd += f'--env USER={os.getenv("USER", "root")} ' + #cmd += f'--cpus "{self.config.get("runtime_cpu")}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--cpuset-cpus="0-{self.config.get("runtime_cpu")-1}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--memory "{self.config.get("runtime_memory")}m" ' if self.config.get('runtime_memory') else '' cmd += f'--rm -v {tmp_path}:/tmp --entrypoint "python3" ' cmd += f'{self.runtime_name} /tmp/{USER_TEMP_DIR}/localhost-runner.py get_metadata' + logger.info(cmd) + process = sp.run( shlex.split(cmd), check=True, stdout=sp.PIPE, universal_newlines=True, start_new_session=True @@ -370,9 +376,14 @@ def run_job(self, job_key, job_filename): cmd += '--gpus all ' if self.use_gpu else '' cmd += f'--user {self.uid}:{self.gid} ' if self.is_unix_system and not self.is_podman else '' cmd += f'--env USER={os.getenv("USER", "root")} ' + # cmd += f'--cpus "{self.config.get("runtime_cpu")}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--cpuset-cpus="0-{self.config.get("runtime_cpu")-1}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--memory "{self.config.get("runtime_memory")}m" ' if self.config.get('runtime_memory') else '' cmd += f'--rm -v {tmp_path}:/tmp --entrypoint "python3" ' cmd += f'{self.runtime_name} /tmp/{USER_TEMP_DIR}/localhost-runner.py run_job {job_filename}' + logger.info(cmd) + process = sp.Popen(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE, start_new_session=True) self.jobs[job_key] = process diff --git a/lithops/localhost/v2/localhost.py b/lithops/localhost/v2/localhost.py index a873104a..922cd389 100644 --- a/lithops/localhost/v2/localhost.py +++ b/lithops/localhost/v2/localhost.py @@ -384,6 +384,10 @@ def setup(self): check=True, stdout=sp.PIPE, universal_newlines=True ) + def _get_memory_limit(self): + # with os + return self.config.get('runtime_memory', '512') + def get_metadata(self): if not os.path.isfile(RUNNER_FILE): self.setup() @@ -395,9 +399,14 @@ def get_metadata(self): cmd = f'{self.docker_path} run --name lithops_metadata ' cmd += f'--user {self.uid}:{self.gid} ' if self.is_unix_system and not self.is_podman else '' cmd += f'--env USER={os.getenv("USER", "root")} ' + #cmd += f'--cpus "{self.config.get("runtime_cpu")}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--cpuset-cpus="0-{self.config.get("runtime_cpu")-1}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--memory "{self.config.get("runtime_memory")}m" ' if self.config.get('runtime_memory') else '' cmd += f'--rm -v {tmp_path}:/tmp --entrypoint "python3" ' cmd += f'{self.runtime_name} /tmp/{USER_TEMP_DIR}/localhost-runner.py get_metadata' + logger.info(cmd) + process = sp.run( shlex.split(cmd), check=True, stdout=sp.PIPE, universal_newlines=True, start_new_session=True @@ -416,9 +425,14 @@ def start(self): cmd += '--gpus all ' if self.use_gpu else '' cmd += f'--user {self.uid}:{self.gid} ' if self.is_unix_system and not self.is_podman else '' cmd += f'--env USER={os.getenv("USER", "root")} ' + #cmd += f'--cpus "{self.config.get("runtime_cpu")}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--cpuset-cpus="0-{self.config.get("runtime_cpu")-1}" ' if self.config.get('runtime_cpu') else '' + cmd += f'--memory "{self.config.get("runtime_memory")}m" ' if self.config.get('runtime_memory') else '' cmd += f'--rm -v {tmp_path}:/tmp -it --detach ' cmd += f'--entrypoint=/bin/bash {self.runtime_name}' + logger.info(cmd) + self.container_process = sp.Popen(shlex.split(cmd), stdout=sp.DEVNULL, start_new_session=True) self.container_process.communicate() # blocks until the process finishes