-
Notifications
You must be signed in to change notification settings - Fork 373
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
Fix performance issues with JRuby #647
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this iterate over all ActiveRecord connections? Regardless if they were made with
ActiveRecord::Base.establish_connection
, or from a class that inherits fromActiveRecord::Base
? Just want to make sure connections configured in a legitimate way for Rails don't slip through the cracks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep all there is connected (in whatever way) with AR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, but I'm not sure, that it's all connections in the current process, because here's how
connection_pool_list
is defined (at least in Rails 4.2):and here's how
owner_to_pool
is defined:If I understand well (and I'm absolutely not sure of that) this line of code:
@owner_to_pool[Process.pid]
, it says that it takes the pools for the current process only.Which means that for a multi-processes runtime (like Puma with workers or Unicorn) the number of connections should be fairly low (at least, it's my assumption. I know that AR is by default configured to use 5 connections, IIRC)
And for a multi-threaded runtime (like Puma with JRuby) it means all the connections but it seems that in this case AR uses only one connection per thread (maybe per db) which is again fairly small (I think 😕).
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you got that right: one connection per thread
per Model.establish_connection (
class_to_pool
) - which usually means a different DB connection.Process.pid
is really only due MRI - not much forking under JRuby.under a multi-process (MRI) connections are low (usually ~1 since one process == one request), under a GIL-less runtime it can go as high as the server handles concurrent requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kares Clever that since its segmented by process/thread that it makes the pool to be searched much smaller. I think this is only problematic if the AR event is generated from one thread, and handled in another, which would cause it to search the wrong pool. I can't really think of how that would happen here.
@guizmaii Okay, so I guess my last concern is, does this work with Rails 3.0 - latest? We have broken tests in this PR so its hard to tell. If we can get the build passing, it will run the Rails tests for these different versions, and that would be good enough to tell me whether this condition has been satisfied.