Really fiber-aware ActiveRecord connection pool and em_mysql2 adapter#179
Really fiber-aware ActiveRecord connection pool and em_mysql2 adapter#179dmgtn wants to merge 2 commits intoigrigorik:masterfrom
Conversation
|
Looks to be much simpler implementation, which is a good sign. That said, would be great to get 4.0 support! Any chance you could give it a shot and see what the delta is (if any)? |
|
@mrms-dos @igrigorik I have some questions Am I right that everything should work without defining custom adapters if we just: $VERBOSE.tap do |old_verbose|
$VERBOSE = nil
Mysql2::Client = Mysql2::EM::Client
$VERBOSE = old_verbose
endIt's really dirty but doing copy-paste of some of the |
|
What was the motivation of stubbing UPD: In ActiveRecord 4.x
I think we should not stub We also can implement module ActiveRecord
module ConnectionAdapters
class ConnectionPool
if ActiveRecord::VERSION::MAJOR == 4
class Reaper
def run
return unless frequency
EM::Synchrony.add_periodic_timer(frequency) do
pool.reap
end
end
end
end
end
end
endIt would be useful! But we cannot backport it to ActiveRecord 3.x, so |
ActiveRecord::Base.connection_id ||= Fiber.current.object_idTaking UPD: sorry, i just realized that |
|
Now i'm trying to use The little difference coming from 4.2 is: module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
include EventMachine::Synchrony::MonitorMixin
if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [4, 2]
def lease
synchronize do
unless in_use?
@owner = Fiber.current
end
end
end
end
end
end
endFor PostgreSQL users: require 'em-pg-client'
$VERBOSE.tap do |old_verbose|
$VERBOSE = nil
PGconn = PG::EM::Client
$VERBOSE = old_verbose
end |
|
Please see #190 |
|
@mrms-dos @marshall-lee Please merge the current master in your pull request branches, or rebase on top of it, so that they build on Travis, and we can see how the specs pass on different ActiveRecord versions. |
This implementation supports concurrent running transactions. We tested it with active_record 3.2, but did not test with 4.0. We are using it in production and it is working well.
ActiveRecord have already had good connection pooling, that uses Thread.current[] for thread-aware (and fiber-aware) storage. We replaced original MonitorMixin, by fiber-aware one, and thats all.