oldmoe / mysqlplus

An enhanced mysql driver with an async interface and threaded access support

This URL has Read+Write access

mysqlplus / test / all_hashes_test.rb
100644 38 lines (27 sloc) 0.669 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'create_test_db'
 
use_the_all_hashes_method = true
 
$count = 5
 
$start = Time.now
 
$connections = []
$count.times do
  $connections << Mysql.real_connect('localhost','root', '', 'local_test_db')
end
 
 
$threads = []
$count.times do |i|
  $threads << Thread.new do
 
    query = "select * from test_table"
    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