Skip to content

Commit

Permalink
feat(runtime): Set server process to run with highest system priority (
Browse files Browse the repository at this point in the history
…All-Hands-AI#5206)

Co-authored-by: openhands <[email protected]>
Co-authored-by: Robert Brennan <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 98b2994 commit 7db0a35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions openhands/runtime/impl/modal/modal_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def _init_sandbox(
self.config.sandbox.user_id,
plugin_args,
browsergym_args,
is_root=not self.config.run_as_openhands, # is_root=True when running as root
)
self.log('debug', f'Starting container with command: {sandbox_start_cmd}')
self.sandbox = modal.Sandbox.create(
Expand Down
1 change: 1 addition & 0 deletions openhands/runtime/impl/remote/remote_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def _start_runtime(self):
self.config.sandbox.user_id,
plugin_args,
browsergym_args,
is_root=not self.config.run_as_openhands, # is_root=True when running as root
)
start_request = {
'image': self.container_image,
Expand Down
1 change: 1 addition & 0 deletions openhands/runtime/impl/runloop/runloop_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _create_new_devbox(self) -> DevboxView:
self.config.sandbox.user_id,
plugin_args,
browsergym_args,
is_root=not self.config.run_as_openhands, # is_root=True when running as root
)

# Add some additional commands based on our image
Expand Down
18 changes: 17 additions & 1 deletion openhands/runtime/utils/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ def get_remote_startup_command(
user_id: int,
plugin_args: list[str],
browsergym_args: list[str],
is_root: bool = False,
):
return [
base_cmd = [
'/openhands/micromamba/bin/micromamba',
'run',
'-n',
Expand All @@ -27,3 +28,18 @@ def get_remote_startup_command(
str(user_id),
*browsergym_args,
]

if is_root:
# If running as root, set highest priority and lowest OOM score
cmd_str = ' '.join(base_cmd)
return [
'nice',
'-n',
'-20', # Highest priority
'sh',
'-c',
f'echo -1000 > /proc/self/oom_score_adj && exec {cmd_str}'
]
else:
# If not root, run with normal priority
return base_cmd

0 comments on commit 7db0a35

Please sign in to comment.