File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 11import json
2+ import os
23from collections .abc import Sequence
34from enum import Enum
45from typing import Literal , Optional
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+
2129class 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
Original file line number Diff line number Diff line change 11import math
2- import os
32import random
43import time
54from 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 :
You can’t perform that action at this time.
0 commit comments