Skip to content

Instantly share code, notes, and snippets.

@vitobotta
Created July 8, 2011 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitobotta/1071717 to your computer and use it in GitHub Desktop.
Save vitobotta/1071717 to your computer and use it in GitHub Desktop.
Connection pool testing with JRuby and MRI
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