diff --git a/dbgpt/_private/config.py b/dbgpt/_private/config.py index 84d79494f..cd7936a60 100644 --- a/dbgpt/_private/config.py +++ b/dbgpt/_private/config.py @@ -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": diff --git a/dbgpt/app/component_configs.py b/dbgpt/app/component_configs.py index 29c9e59be..a8a0f24d1 100644 --- a/dbgpt/app/component_configs.py +++ b/dbgpt/app/component_configs.py @@ -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) diff --git a/dbgpt/app/initialization/serve_initialization.py b/dbgpt/app/initialization/serve_initialization.py index fcdf6600f..b88d1d215 100644 --- a/dbgpt/app/initialization/serve_initialization.py +++ b/dbgpt/app/initialization/serve_initialization.py @@ -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