Performance: Connection pooling
HIGH IMPACT
Connection pooling affects how quickly the server can handle database requests by reusing open connections instead of opening new ones each time.
from asyncpg import create_pool pool = await create_pool(dsn) async def get_data(): async with pool.acquire() as conn: result = await conn.fetch('SELECT * FROM table') return result
async def get_data(): conn = await asyncpg.connect(dsn) result = await conn.fetch('SELECT * FROM table') await conn.close() return result
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No connection pooling (new connection per request) | N/A | N/A | N/A | [X] Bad |
| Using connection pooling with asyncpg in FastAPI | N/A | N/A | N/A | [OK] Good |