Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lithops/localhost/v1/localhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
14 changes: 14 additions & 0 deletions lithops/localhost/v2/localhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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

Expand Down
Loading