feat(asyncio): async DB layer, budget strategies, and log writer#35
Merged
feat(asyncio): async DB layer, budget strategies, and log writer#35
Conversation
…og writer Swap synchronous psycopg2 + Session for asyncpg + AsyncSession across the entire gateway. Contended DB calls now yield to the event loop instead of blocking it. Key changes: - create_engine -> create_async_engine with configurable pool sizing - sessionmaker -> async_sessionmaker(expire_on_commit=False) - All route handlers, services, repositories converted to async DB calls - budget_strategy config: 'for_update' (default), 'cas' (lock-free), 'disabled' - log_writer_strategy config: 'single' (inline), 'batch' (background flush) - LogWriter Protocol with SingleLogWriter and BatchLogWriter implementations - DB pool tuning: db_pool_size, db_max_overflow, db_pool_timeout, db_pool_recycle - App startup uses FastAPI lifespan for async initialization - Alembic migrations remain sync (psycopg2) - New Prometheus metrics for log writer queue/batch/flush Co-Authored-By: Julian Bright <brightsparc@gmail.com>
Contributor
|
@tbille looks like you didn't bring over the load testing script - I think that could still be useful, should I create a PR ? |
Contributor
Author
|
@brightsparc good catch. Can you make a PR, I'll review it today |
Contributor
Here is the PR, I also noticed a small bug when re-running, so added graceful shutdown to capture all logs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
psycopg2+Sessionto asyncasyncpg+AsyncSession. Contended DB calls now yield to the event loop instead of blocking it.budget_strategyconfig:for_update(default/legacy),cas(lock-free, recommended),disabled(skip budget checks)log_writer_strategyconfig:single(inline, default),batch(background flush for high-throughput)db_pool_size,db_max_overflow,db_pool_timeout,db_pool_recyclePorted from mozilla-ai/any-llm#1001
Co-Authored-By: Julian Bright brightsparc@gmail.com