clean up async_query/threaded test

This commit is contained in:
Aman Gupta 2008-08-27 14:23:01 -07:00
parent da40f34362
commit aa35d6430f

View File

@ -2,21 +2,28 @@ require 'mysqlplus'
$t = Time.now $t = Time.now
$connections = [] $connections = []
$threads = []
$count = 10 $count = 10
$count.times do $count.times do
$connections << Mysql.real_connect('localhost','root') $connections << Mysql.real_connect('localhost','root')
end end
puts 'connection pool ready'
$done = 0 $done = 0
$t = Time.now
$count.times do |i| $count.times do |i|
Thread.new do $threads << Thread.new do
$connections[i].async_query('select sleep(1)').each{|r|puts "#{i}:#{r}"} puts "sending query on connection #{i}"
$connections[i].async_query("select sleep(3)").each{ |r|
puts "connection #{i} done"
}
$done = $done + 1 $done = $done + 1
puts Time.now - $t if $done == $count
end end
end end
loop do puts 'waiting on threads'
break if $done == $count $threads.each{|t| t.join }
end
puts (Time.now - $t) if $done == $count