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

DB Pool Updates #103

Merged
merged 20 commits into from
Sep 13, 2024
Merged

DB Pool Updates #103

merged 20 commits into from
Sep 13, 2024

Conversation

rsamoilov
Copy link
Member

@rsamoilov rsamoilov commented Sep 1, 2024

DB Pool Updates

Description

This is the prep work to have Rage's DB Pool enabled by default in v1.10.0.

Weak AR connections

The PR changes the logic behind Fiber.defer to automatically release Active Record connections without waiting for the request to complete. Previous approach (see #66 and #80) was unstable with AR 7.0+. The new approach keeps track of the file descriptors the scheduler waits on to release the connection once the code proceeds to the next blocking call.

Health checks for AR connections

With Active Record < 7.1, we enable active health checks for the DB connections that will run every second. If a connection is identified as unhealthy, the pool will reconnect the next time it is checked out. We are not going with the native Active Record approach of calling verify! every time the connection is checked out because active health checks strike a better balance between availability and performance.
The health checks are only enabled with AR < 7.1, as AR 7.1+ automatically reconnects to the database.

Other fixes

Some other fixes include the correct handling of the idle_timeout option and updating the code to automatically release AR connections from all connection pools. The Fiber Scheduler is also updated to correctly handle automatic reconnects and query retries in AR 7.1+.

the new method postpones releasing the connection to the next iteration of the event loop and only releases it if the file descriptor has changed since the last `io_wait` call. This ensures we are not releasing the connection until the DB query is completed (there can be several `io_wait` calls for one query)

The change is mostly caused by the bug in AR 7.0+ that makes the inital `Fiber.defer` approach unstable.

We also disable the method for AR 7.2+, as it doesn't hold onto connections anymore.
AR 6.0 doesn't support passing the role to the connection handler methods
@rsamoilov rsamoilov changed the title Standalone db DB Pool Updates Sep 1, 2024
@rsamoilov rsamoilov merged commit 06da72c into master Sep 13, 2024
6 checks passed
@rsamoilov rsamoilov deleted the standalone-db branch September 13, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant