Commit f62a541ca1650b1fbd8a48406697ccbe6e49047a

Authored by tangwang
1 parent 791a7909

将 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 个线程
添加日志记录
Showing 2 changed files with 18 additions and 0 deletions   Show diff stats
api/app.py
... ... @@ -177,6 +177,15 @@ app.add_middleware(
177 177 @app.on_event("startup")
178 178 async def startup_event():
179 179 """Initialize service on startup."""
  180 + # Configure thread pool size for uvicorn (default is 40, set to 48)
  181 + try:
  182 + import anyio.to_thread
  183 + limiter = anyio.to_thread.current_default_thread_limiter()
  184 + limiter.total_tokens = 48
  185 + logger.info(f"Thread pool size set to {limiter.total_tokens}")
  186 + except Exception as e:
  187 + logger.warning(f"Failed to set thread pool size: {e}, using default")
  188 +
180 189 es_host = os.getenv("ES_HOST", "http://localhost:9200")
181 190 logger.info("Starting E-Commerce Search API (Multi-Tenant)")
182 191 logger.info(f"Elasticsearch Host: {es_host}")
... ...
api/indexer_app.py
... ... @@ -150,6 +150,15 @@ app = FastAPI(
150 150  
151 151 @app.on_event("startup")
152 152 async def startup_event():
  153 + # Configure thread pool size for uvicorn (default is 40, set to 48)
  154 + try:
  155 + import anyio.to_thread
  156 + limiter = anyio.to_thread.current_default_thread_limiter()
  157 + limiter.total_tokens = 48
  158 + logger.info(f"Thread pool size set to {limiter.total_tokens}")
  159 + except Exception as e:
  160 + logger.warning(f"Failed to set thread pool size: {e}, using default")
  161 +
153 162 es_host = os.getenv("ES_HOST", "http://localhost:9200")
154 163 logger.info("Starting Indexer API service")
155 164 logger.info(f"Elasticsearch Host: {es_host}")
... ...