mysqlplus/test/test_threaded.rb

30 lines
478 B
Ruby
Raw Normal View History

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