Skip to content

Commit 681d505

Browse files
committed
Set default worker process limit based on number of CPUs
Signed-off-by: Samuel Monson <[email protected]>
1 parent bcc2f8c commit 681d505

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/guidellm/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
from collections.abc import Sequence
34
from enum import Enum
45
from typing import Literal, Optional
@@ -18,6 +19,13 @@
1819
]
1920

2021

22+
def get_avail_cpu() -> int:
23+
"""
24+
Get the maximum number of worker processes based on the CPU count
25+
"""
26+
return max(1, os.cpu_count() or 1) - 1
27+
28+
2129
class Environment(str, Enum):
2230
"""
2331
Enum for the supported environments
@@ -131,7 +139,9 @@ class Settings(BaseSettings):
131139

132140
# Scheduler settings
133141
max_concurrency: int = 512
134-
max_worker_processes: int = 10
142+
max_worker_processes: int = Field(
143+
default_factory=lambda: max((os.cpu_count() or 1) - 1, 10)
144+
)
135145
max_add_requests_per_loop: int = 20
136146
scheduler_start_delay: float = 5
137147

src/guidellm/scheduler/strategy.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import math
2-
import os
32
import random
43
import time
54
from collections.abc import Generator
@@ -72,9 +71,7 @@ def processes_limit(self) -> int:
7271
7372
:return: The number of processes for the scheduling strategy.
7473
"""
75-
cpu_cores = os.cpu_count() or 1
76-
77-
return min(max(1, cpu_cores - 1), settings.max_worker_processes)
74+
return settings.max_worker_processes
7875

7976
@property
8077
def queued_requests_limit(self) -> Optional[int]:
@@ -231,9 +228,8 @@ def processes_limit(self) -> int:
231228
:return: {self.streams} for the concurrent scheduling strategy to limit
232229
the worker processes to the number of streams.
233230
"""
234-
cpu_cores = os.cpu_count() or 1
235231

236-
return min(max(1, cpu_cores - 1), self.streams)
232+
return min(self.streams, settings.max_worker_processes)
237233

238234
@property
239235
def queued_requests_limit(self) -> int:

0 commit comments

Comments
 (0)