Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heavily revise the implementation of EventLoopConnectionPool #102

Merged
merged 2 commits into from
Aug 13, 2023

Conversation

gwynne
Copy link
Member

@gwynne gwynne commented Aug 11, 2023

Overview

This is a temporary stopgap measure to clean up some of the more extant issues with the existing implementation, pending the integration of a much more robust and advanced connection pool solution.

While technically there is no change in the public API surface, this is nonetheless being marked as semver-minor due to the significant changes in behavior. This PR has already revealed a query ordering bug in the Fluent benchmarks just by behaving more correctly.

This should hopefully fix the issue described in #101, but I haven't been able to locally reproduce the race condition despite being fairly sure as to its cause, so I can't verify.

More details

  • Now uses Deque instead of the obsolete CircularBuffer for tracking available connections
  • Now uses an OrderedDictionary and numeric waiter IDs to track waitlists rather than the obsolete CircularBuffer
  • Checking for on-EventLoop execution is now handled more idomatically
  • Queries are now always served in order instead of new queries getting priority over those already on the waitlist when a new connection becomes available
  • Removing completed waiters from the waitlist and cancelling their timeouts is now considerably more reliable
  • If more than one connection has become available when a connection is released, multiple waiters are now serviced immediately
  • Waiters that are still waiting during pool shutdown no longer emit spurious request timeout logs
  • The time taken to establish a new database connection (if needed) now counts against a waiter's timeout duration (making the duration much more accurate)

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2023

Codecov Report

Merging #102 (deda984) into main (4ee8c97) will decrease coverage by 0.07%.
Report is 1 commits behind head on main.
The diff coverage is 95.78%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
- Coverage   95.70%   95.63%   -0.07%     
==========================================
  Files          19       19              
  Lines         955      963       +8     
==========================================
+ Hits          914      921       +7     
- Misses         41       42       +1     
Files Changed Coverage Δ
...ncKit/ConnectionPool/EventLoopConnectionPool.swift 94.85% <95.78%> (-0.46%) ⬇️

gwynne added a commit to vapor/fluent-kit that referenced this pull request Aug 11, 2023
Fix a migration missing an important deletion in its revert that was revealed by vapor/async-kit#102
@gwynne
Copy link
Member Author

gwynne commented Aug 11, 2023

Holding off on merging this until @0xTim can glance at it too, given how fundamental this awful code is to Fluent.

Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

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

LGTM - one query but nothing major

@gwynne gwynne merged commit eab9edf into main Aug 13, 2023
12 checks passed
@gwynne gwynne deleted the improve-connection-pool branch August 13, 2023 12:55
@penny-for-vapor
Copy link

These changes are now available in 1.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Contains new APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants