2008-08-27 12:09:39 +00:00
|
|
|
require 'mysqlplus'
|
2008-08-26 23:05:20 +00:00
|
|
|
|
|
|
|
$count = 10
|
|
|
|
|
2008-08-27 23:11:19 +00:00
|
|
|
$start = Time.now
|
|
|
|
|
|
|
|
$connections = []
|
2008-08-26 23:05:20 +00:00
|
|
|
$count.times do
|
2008-08-27 21:23:01 +00:00
|
|
|
$connections << Mysql.real_connect('localhost','root')
|
2008-08-26 23:05:20 +00:00
|
|
|
end
|
2008-08-27 21:23:01 +00:00
|
|
|
|
|
|
|
puts 'connection pool ready'
|
|
|
|
|
2008-08-27 23:11:19 +00:00
|
|
|
$threads = []
|
2008-08-26 23:05:20 +00:00
|
|
|
$count.times do |i|
|
2008-08-27 21:23:01 +00:00
|
|
|
$threads << Thread.new do
|
2008-08-27 23:11:19 +00:00
|
|
|
|
2008-08-27 21:23:01 +00:00
|
|
|
puts "sending query on connection #{i}"
|
2008-08-27 23:11:19 +00:00
|
|
|
|
2008-08-27 21:23:01 +00:00
|
|
|
$connections[i].async_query("select sleep(3)").each{ |r|
|
|
|
|
puts "connection #{i} done"
|
|
|
|
}
|
2008-08-27 23:11:19 +00:00
|
|
|
|
2008-08-26 23:05:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-08-27 21:23:01 +00:00
|
|
|
puts 'waiting on threads'
|
|
|
|
$threads.each{|t| t.join }
|
|
|
|
|
2008-08-27 23:11:19 +00:00
|
|
|
puts Time.now - $start
|