feat(core): Add multi-instance config

This commit is contained in:
Fangyin Cheng
2024-08-19 08:39:09 +08:00
parent 354a8ac3aa
commit 85369a55a7
3 changed files with 10 additions and 2 deletions

View File

@@ -327,6 +327,10 @@ class Config(metaclass=Singleton):
self.FILE_SERVER_LOCAL_STORAGE_PATH = os.getenv(
"FILE_SERVER_LOCAL_STORAGE_PATH"
)
# multi-instance flag
self.WEBSERVER_MULTI_INSTANCE = (
os.getenv("MULTI_INSTANCE", "False").lower() == "true"
)
@property
def local_db_manager(self) -> "ConnectorManager":

View File

@@ -52,7 +52,7 @@ def initialize_components(
param, system_app, embedding_model_name, embedding_model_path
)
_initialize_rerank_model(param, system_app, rerank_model_name, rerank_model_path)
_initialize_model_cache(system_app)
_initialize_model_cache(system_app, param.port)
_initialize_awel(system_app, param)
# Initialize resource manager of agent
_initialize_resource_manager(system_app)
@@ -62,7 +62,7 @@ def initialize_components(
register_serve_apps(system_app, CFG, param.port)
def _initialize_model_cache(system_app: SystemApp):
def _initialize_model_cache(system_app: SystemApp, port: int):
from dbgpt.storage.cache import initialize_cache
if not CFG.MODEL_CACHE_ENABLE:
@@ -72,6 +72,8 @@ def _initialize_model_cache(system_app: SystemApp):
storage_type = CFG.MODEL_CACHE_STORAGE_TYPE or "disk"
max_memory_mb = CFG.MODEL_CACHE_MAX_MEMORY_MB or 256
persist_dir = CFG.MODEL_CACHE_STORAGE_DISK_DIR or MODEL_DISK_CACHE_DIR
if CFG.WEBSERVER_MULTI_INSTANCE:
persist_dir = f"{persist_dir}_{port}"
initialize_cache(system_app, storage_type, max_memory_mb, persist_dir)

View File

@@ -94,6 +94,8 @@ def register_serve_apps(system_app: SystemApp, cfg: Config, webserver_port: int)
local_storage_path = (
cfg.FILE_SERVER_LOCAL_STORAGE_PATH or FILE_SERVER_LOCAL_STORAGE_PATH
)
if cfg.WEBSERVER_MULTI_INSTANCE:
local_storage_path = f"{local_storage_path}_{webserver_port}"
# Set config
system_app.config.set(
f"{FILE_SERVE_CONFIG_KEY_PREFIX}local_storage_path", local_storage_path