clean up threaded test; add simple sequel test
This commit is contained in:
parent
aa35d6430f
commit
4fb06ca803
@ -1,29 +1,30 @@
|
||||
require 'mysqlplus'
|
||||
|
||||
$t = Time.now
|
||||
$connections = []
|
||||
$threads = []
|
||||
$count = 10
|
||||
|
||||
$start = Time.now
|
||||
|
||||
$connections = []
|
||||
$count.times do
|
||||
$connections << Mysql.real_connect('localhost','root')
|
||||
end
|
||||
|
||||
puts 'connection pool ready'
|
||||
|
||||
$done = 0
|
||||
|
||||
$threads = []
|
||||
$count.times do |i|
|
||||
$threads << Thread.new do
|
||||
|
||||
puts "sending query on connection #{i}"
|
||||
|
||||
$connections[i].async_query("select sleep(3)").each{ |r|
|
||||
puts "connection #{i} done"
|
||||
}
|
||||
$done = $done + 1
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
puts 'waiting on threads'
|
||||
$threads.each{|t| t.join }
|
||||
|
||||
puts (Time.now - $t) if $done == $count
|
||||
puts Time.now - $start
|
24
test/test_threaded_sequel.rb
Normal file
24
test/test_threaded_sequel.rb
Normal file
@ -0,0 +1,24 @@
|
||||
require 'rubygems'
|
||||
require 'sequel'
|
||||
|
||||
require 'mysqlplus'
|
||||
class Mysql
|
||||
unless method_defined? :sync_query
|
||||
alias :sync_query :query
|
||||
alias :query :async_query
|
||||
end
|
||||
end
|
||||
|
||||
DB = Sequel.connect('mysql://root@localhost', :max_connections => 20)
|
||||
|
||||
start = Time.now
|
||||
|
||||
(0..10).map do
|
||||
Thread.new do
|
||||
|
||||
p DB['select sleep(2)'].all
|
||||
|
||||
end
|
||||
end.map{|t| t.join }
|
||||
|
||||
p (Time.now - start)
|
Loading…
Reference in New Issue
Block a user