performance: db/aiohttp connection pooling
This commit is contained in:
17
base.py
17
base.py
@@ -4,12 +4,23 @@ import sys
|
||||
sys.path.insert(0, ".")
|
||||
import logging
|
||||
import asyncio
|
||||
|
||||
# Install uvloop for better async performance (2-4x speedup on I/O)
|
||||
try:
|
||||
import uvloop
|
||||
|
||||
uvloop.install()
|
||||
logging.info("uvloop installed successfully")
|
||||
except ImportError:
|
||||
logging.warning("uvloop not available, using default asyncio event loop")
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Any
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from scalar_fastapi import get_scalar_api_reference
|
||||
from lyric_search.sources import redis_cache
|
||||
import shared # Shared connection pools
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.getLogger("aiosqlite").setLevel(logging.WARNING)
|
||||
@@ -35,6 +46,9 @@ async def lifespan(app: FastAPI):
|
||||
uvicorn_access_logger = logging.getLogger("uvicorn.access")
|
||||
uvicorn_access_logger.disabled = True
|
||||
|
||||
# Initialize shared infrastructure (Redis pool, aiohttp session, SQLite pool)
|
||||
await shared.startup()
|
||||
|
||||
# Start Radio playlists
|
||||
if "radio" in _routes and hasattr(_routes["radio"], "on_start"):
|
||||
await _routes["radio"].on_start()
|
||||
@@ -55,6 +69,9 @@ async def lifespan(app: FastAPI):
|
||||
if "trip" in _routes and hasattr(_routes["trip"], "shutdown"):
|
||||
await _routes["trip"].shutdown()
|
||||
|
||||
# Clean up shared infrastructure
|
||||
await shared.shutdown()
|
||||
|
||||
logger.info("Application shutdown complete")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user