mysqlplus/test/test_threaded.rb

29 lines
520 B
Ruby
Raw Normal View History

require 'mysqlplus'
2008-08-26 23:05:20 +00:00
$t = Time.now
$connections = []
2008-08-27 21:23:01 +00:00
$threads = []
2008-08-26 23:05:20 +00:00
$count = 10
$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-26 23:05:20 +00:00
$done = 0
2008-08-27 21:23:01 +00:00
2008-08-26 23:05:20 +00:00
$count.times do |i|
2008-08-27 21:23:01 +00:00
$threads << Thread.new do
puts "sending query on connection #{i}"
$connections[i].async_query("select sleep(3)").each{ |r|
puts "connection #{i} done"
}
2008-08-26 23:05:20 +00:00
$done = $done + 1
end
end
2008-08-27 21:23:01 +00:00
puts 'waiting on threads'
$threads.each{|t| t.join }
puts (Time.now - $t) if $done == $count