Skip to content

Conversation

@galvana
Copy link
Contributor

@galvana galvana commented Dec 17, 2025

Description Of Changes

Pre-warming async connection pool to prevent expensive type introspection on first connection usage. Local performance tests showed the type introspection taking up to 7 seconds on a busy database. This thread suggests disabling jit but we figured that's a change we'd want to run a broader performance test for.

Steps to Confirm

  1. The server should start up. You'll see this in the server-startup logs
Async connection pool warmup completed successfully

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

@galvana galvana requested a review from a team as a code owner December 17, 2025 00:26
@galvana galvana requested review from vcruces and removed request for a team December 17, 2025 00:26
@vercel
Copy link

vercel bot commented Dec 17, 2025

Deployment failed with the following error:

You must set up Two-Factor Authentication before accessing this team.

View Documentation: https://vercel.com/docs/two-factor-authentication

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 17, 2025

Greptile Overview

Greptile Summary

Pre-warms the async connection pool during server startup to prevent expensive type introspection (up to 7 seconds) on first connection usage. The warmup creates connections up to pool_size (default 50) concurrently and validates each with a simple query.

  • Added warmup_async_pool() function in src/fides/api/db/ctl_session.py:71-107 that creates connections concurrently using asyncio.gather
  • Integrated into server startup lifecycle in src/fides/api/main.py:93 after database startup and before Redis check
  • Includes graceful error handling with warnings for individual connection failures
  • Found one logic issue: asyncio.gather() needs return_exceptions=True to properly handle all connection failures without stopping the warmup process

Confidence Score: 4/5

  • This PR is safe to merge with one minor fix needed for exception handling
  • The implementation is sound with proper logging, graceful error handling, and appropriate placement in the startup sequence. However, the asyncio.gather() call needs return_exceptions=True to properly continue warming up connections even if some fail, which is the intended behavior based on the comments
  • src/fides/api/db/ctl_session.py requires a one-line fix to add return_exceptions=True parameter

Important Files Changed

File Analysis

Filename Score Overview
src/fides/api/db/ctl_session.py 4/5 Added async connection pool warmup function to pre-create connections and reduce type introspection latency. Minor issue with exception handling in asyncio.gather.
src/fides/api/main.py 5/5 Called warmup_async_pool during server startup lifespan, positioned appropriately after database startup and before Redis check.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@galvana galvana requested review from erosselli and johnewart and removed request for vcruces December 17, 2025 00:29
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Collaborator

@johnewart johnewart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Should we do the same for the synchronous pool at some point?

Copy link
Contributor

@erosselli erosselli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, let's add a changelog

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.29%. Comparing base (c8af6ca) to head (62e5e04).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/fides/api/db/ctl_session.py 75.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7141      +/-   ##
==========================================
- Coverage   87.30%   87.29%   -0.01%     
==========================================
  Files         533      533              
  Lines       35095    35116      +21     
  Branches     4067     4068       +1     
==========================================
+ Hits        30640    30656      +16     
- Misses       3570     3574       +4     
- Partials      885      886       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@galvana galvana enabled auto-merge December 17, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants