Add support for configuring FastAPI/AnyIO Thread Pool Size

This commit is contained in:
Juan Calderon-Perez
2025-04-18 09:22:23 -04:00
parent b8fb4e528d
commit 19b3d88737
4 changed files with 21 additions and 5 deletions

View File

@@ -11,6 +11,8 @@ import random
from contextlib import asynccontextmanager
from urllib.parse import urlencode, parse_qs, urlparse
import anyio
import anyio.to_thread
from pydantic import BaseModel
from sqlalchemy import text
@@ -106,6 +108,8 @@ from open_webui.config import (
OPENAI_API_CONFIGS,
# Direct Connections
ENABLE_DIRECT_CONNECTIONS,
# Thread pool size for FastAPI/AnyIO
THREAD_POOL_SIZE,
# Tool Server Configs
TOOL_SERVER_CONNECTIONS,
# Code Execution
@@ -434,6 +438,10 @@ async def lifespan(app: FastAPI):
if LICENSE_KEY:
get_license_data(app, LICENSE_KEY)
pool_size = THREAD_POOL_SIZE
if pool_size and pool_size > 0:
anyio.to_thread.current_default_thread_limiter().total_tokens = pool_size
asyncio.create_task(periodic_usage_pool_cleanup())
yield