2009-04-18 22:55:17 +00:00
|
|
|
require 'create_test_db'
|
2008-09-02 17:19:04 +00:00
|
|
|
|
|
|
|
use_the_all_hashes_method = true
|
|
|
|
|
|
|
|
$count = 5
|
|
|
|
|
|
|
|
$start = Time.now
|
|
|
|
|
|
|
|
$connections = []
|
|
|
|
$count.times do
|
2009-04-18 22:50:45 +00:00
|
|
|
$connections << Mysql.real_connect('localhost','root', '', 'local_test_db')
|
2008-09-02 17:19:04 +00:00
|
|
|
end
|
|
|
|
|
2009-04-18 22:50:45 +00:00
|
|
|
|
2008-09-02 17:19:04 +00:00
|
|
|
$threads = []
|
|
|
|
$count.times do |i|
|
|
|
|
$threads << Thread.new do
|
|
|
|
|
2009-04-18 22:50:45 +00:00
|
|
|
query = "select * from test_table"
|
2008-09-02 17:19:04 +00:00
|
|
|
puts "sending query on connection #{i}"
|
|
|
|
conn = $connections[i]
|
|
|
|
result = conn.async_query(query)
|
|
|
|
if use_the_all_hashes_method
|
|
|
|
saved = result.all_hashes
|
|
|
|
else
|
|
|
|
saved = []
|
|
|
|
result.each_hash {|h| saved << h }
|
|
|
|
end
|
|
|
|
result.free
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
puts 'waiting on threads'
|
|
|
|
$threads.each{|t| t.join }
|
|
|
|
|
|
|
|
puts Time.now - $start
|