clean up threaded test; add simple sequel test

This commit is contained in:
Aman Gupta 2008-08-27 16:11:19 -07:00
parent aa35d6430f
commit 4fb06ca803
2 changed files with 32 additions and 7 deletions

View File

@ -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

View 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)