Skip to content

Commit 8bdfc83

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

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/guidellm/config.py

Lines changed: 4 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
@@ -131,7 +132,9 @@ class Settings(BaseSettings):
131132

132133
# Scheduler settings
133134
max_concurrency: int = 512
134-
max_worker_processes: int = 10
135+
max_worker_processes: int = Field(
136+
default_factory=lambda: max((os.cpu_count() or 1) - 1, 10)
137+
)
135138
max_add_requests_per_loop: int = 20
136139
scheduler_start_delay: float = 5
137140

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)