mirror of
https://github.com/g0ldyy/comet.git
synced 2026-01-12 01:16:12 +01:00
refactor: centralize ProcessPoolExecutor worker count calculation to a shared module-level variable
This commit is contained in:
@@ -13,6 +13,10 @@ except ValueError:
|
||||
_mp_context = multiprocessing.get_context("spawn")
|
||||
|
||||
app_executor = None
|
||||
max_workers = settings.EXECUTOR_MAX_WORKERS
|
||||
if max_workers is None:
|
||||
cpu_count = os.cpu_count() or 1
|
||||
max_workers = min(cpu_count, 4)
|
||||
|
||||
|
||||
def worker_initializer():
|
||||
@@ -22,12 +26,6 @@ def worker_initializer():
|
||||
def setup_executor():
|
||||
global app_executor
|
||||
|
||||
max_workers = settings.EXECUTOR_MAX_WORKERS
|
||||
|
||||
if max_workers is None:
|
||||
cpu_count = os.cpu_count() or 1
|
||||
max_workers = min(cpu_count, 4)
|
||||
|
||||
app_executor = ProcessPoolExecutor(
|
||||
max_workers=max_workers, mp_context=_mp_context, initializer=worker_initializer
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from comet.core.execution import max_workers
|
||||
from comet.core.log_levels import (CUSTOM_LOG_LEVELS, STANDARD_LOG_LEVELS,
|
||||
get_level_info)
|
||||
|
||||
@@ -177,13 +177,9 @@ def log_startup_info(settings):
|
||||
)
|
||||
logger.log("COMET", f"Gunicorn Preload App: {settings.GUNICORN_PRELOAD_APP}")
|
||||
|
||||
executor_workers = settings.EXECUTOR_MAX_WORKERS
|
||||
if executor_workers is None:
|
||||
cpu_count = os.cpu_count() or 1
|
||||
executor_workers = min(cpu_count, 4)
|
||||
logger.log(
|
||||
"COMET",
|
||||
f"ProcessPoolExecutor: {executor_workers} workers {'(auto)' if settings.EXECUTOR_MAX_WORKERS is None else ''}",
|
||||
f"ProcessPoolExecutor: {max_workers} workers {'(auto)' if settings.EXECUTOR_MAX_WORKERS is None else ''}",
|
||||
)
|
||||
|
||||
if settings.PUBLIC_BASE_URL:
|
||||
|
||||
Reference in New Issue
Block a user