Created
July 8, 2011 12:22
-
-
Save vitobotta/1071717 to your computer and use it in GitHub Desktop.
Connection pool testing with JRuby and MRI
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
require "rubygems" | |
if defined?(JRUBY_VERSION) | |
gem "activerecord-jdbc-adapter", '>= 1.0.2' | |
gem "activerecord-jdbcmysql-adapter", '>= 1.0.2' | |
gem 'jruby-openssl' | |
gem 'jdbc-mysql' | |
else | |
gem 'mysql2', '= 0.2.7' | |
end | |
require "active_record" | |
require "benchmark" | |
ActiveRecord::Base.establish_connection({ | |
:adapter => "mysql2", | |
:host => "localhost", | |
:username => "root", | |
:database => "onapp_development", | |
:pool => "50", | |
:wait_timeout => 0 | |
}) | |
ActiveRecord::Base.connection.execute("SET GLOBAL max_connections = 500;") | |
threads = [] | |
time = Benchmark.realtime do | |
50.times do | |
threads << Thread.new do | |
ActiveRecord::Base.connection_pool.with_connection do |c| | |
result = c.execute("select connection_id()").first | |
puts "Connection ID: %s" % (defined?(JRUBY_VERSION) ? result["connection_id()"] : result) | |
end | |
end | |
end | |
threads.each{ |t| t.join } | |
end | |
puts "Time elapsed #{time*1000} milliseconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment