From f62a541ca1650b1fbd8a48406697ccbe6e49047a Mon Sep 17 00:00:00 2001 From: tangwang Date: Fri, 19 Dec 2025 09:06:32 +0800 Subject: [PATCH] 将 uvicorn 的默认线程池调整为 48: 1. api/indexer_app.py(索引服务,端口 6004) 在 startup_event() 中添加线程池大小配置 使用 anyio.to_thread.current_default_thread_limiter() 设置线程池大小为 48 添加日志记录,便于确认配置是否生效 2. api/app.py(搜索服务,端口 6002) 在 startup_event() 中添加线程池大小配置 同样设置为 48 个线程 添加日志记录 --- api/app.py | 9 +++++++++ api/indexer_app.py | 9 +++++++++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/api/app.py b/api/app.py index 3a5255e..ab3f9cb 100644 --- a/api/app.py +++ b/api/app.py @@ -177,6 +177,15 @@ app.add_middleware( @app.on_event("startup") async def startup_event(): """Initialize service on startup.""" + # Configure thread pool size for uvicorn (default is 40, set to 48) + try: + import anyio.to_thread + limiter = anyio.to_thread.current_default_thread_limiter() + limiter.total_tokens = 48 + logger.info(f"Thread pool size set to {limiter.total_tokens}") + except Exception as e: + logger.warning(f"Failed to set thread pool size: {e}, using default") + es_host = os.getenv("ES_HOST", "http://localhost:9200") logger.info("Starting E-Commerce Search API (Multi-Tenant)") logger.info(f"Elasticsearch Host: {es_host}") diff --git a/api/indexer_app.py b/api/indexer_app.py index 2de6c51..914ae39 100644 --- a/api/indexer_app.py +++ b/api/indexer_app.py @@ -150,6 +150,15 @@ app = FastAPI( @app.on_event("startup") async def startup_event(): + # Configure thread pool size for uvicorn (default is 40, set to 48) + try: + import anyio.to_thread + limiter = anyio.to_thread.current_default_thread_limiter() + limiter.total_tokens = 48 + logger.info(f"Thread pool size set to {limiter.total_tokens}") + except Exception as e: + logger.warning(f"Failed to set thread pool size: {e}, using default") + es_host = os.getenv("ES_HOST", "http://localhost:9200") logger.info("Starting Indexer API service") logger.info(f"Elasticsearch Host: {es_host}") -- libgit2 0.21.2