mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Make executor max_workers consistent between python versions (#38821)
The default on python 3.8 is for max_workers is significantly lower than the default on python 3.7 which means we can get starved for workers. To determine a reasonable maximum, the maximum was increased to large number on 5 production instances. The number of worker threads created during startup that were needed to avoid waiting for a thread: HOU 1 - 71 HOU 2 - 48 OGG 1 - 60 OGG 2 - 68 OGG 3 - 64 This lead to a selection of 64 as it was reliable in all cases and did not have a significant memory impact
This commit is contained in:
parent
3957337b9f
commit
a6cec21c43
@ -11,6 +11,18 @@ from homeassistant import bootstrap
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.frame import warn_use
|
||||
|
||||
#
|
||||
# Python 3.8 has significantly less workers by default
|
||||
# than Python 3.7. In order to be consistent between
|
||||
# supported versions, we need to set max_workers.
|
||||
#
|
||||
# In most cases the workers are not I/O bound, as they
|
||||
# are sleeping/blocking waiting for data from integrations
|
||||
# updating so this number should be higher than the default
|
||||
# use case.
|
||||
#
|
||||
MAX_EXECUTOR_WORKERS = 64
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class RuntimeConfig:
|
||||
@ -57,7 +69,9 @@ class HassEventLoopPolicy(PolicyBase): # type: ignore
|
||||
if self.debug:
|
||||
loop.set_debug(True)
|
||||
|
||||
executor = ThreadPoolExecutor(thread_name_prefix="SyncWorker")
|
||||
executor = ThreadPoolExecutor(
|
||||
thread_name_prefix="SyncWorker", max_workers=MAX_EXECUTOR_WORKERS
|
||||
)
|
||||
loop.set_default_executor(executor)
|
||||
loop.set_default_executor = warn_use( # type: ignore
|
||||
loop.set_default_executor, "sets default executor on the event loop"
|
||||
|
Loading…
x
Reference in New Issue
Block a user