-
Notifications
You must be signed in to change notification settings - Fork 19
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
DB Pool Updates #103
Conversation
This file contains 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
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
37a4381
to
7ecd879
Compare
7ecd879
to
8e79c56
Compare
releasing connections inside each raises "can't add a new key into hash during iteration"
`:all` option makes it explicit and removes deprecation warning on AR 7.1. AR 6.0 doesn't support this option, so we add the "polyfill"
662cfc8
to
143499f
Compare
setting this flag allows to correctly rebuild connections in dev env with multiple DBs
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.
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+.