Merge branch 'master' of git@github.com:oldmoe/mysqlplus

This commit is contained in:
Roger Pack 2008-09-08 12:10:17 -06:00
commit 6c2b9ecb84
6 changed files with 100 additions and 36 deletions

View File

@ -31,6 +31,10 @@ else
exit 1
end
if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
flags << "-DHAVE_TBR"
end
# make mysql constant
File.open("conftest.c", "w") do |f|
f.puts src

View File

@ -2141,7 +2141,7 @@ void Init_mysql(void)
#endif
rb_define_method(cMysql, "query", query, 1);
rb_define_method(cMysql, "real_query", query, 1);
rb_define_method(cMysql, "async_query", async_query, -1);
rb_define_method(cMysql, "c_async_query", async_query, -1);
rb_define_method(cMysql, "send_query", send_query, 1);
rb_define_method(cMysql, "get_result", get_result, 0);
rb_define_method(cMysql, "readable?", readable, -1);

View File

@ -2,11 +2,7 @@ require 'mysql'
class Mysql
alias_method :c_async_query, :async_query
def async_query(sql, timeout = nil)
puts "** Blocking ? #{blocking?().inspect}" if ENV['MYSQL_BLOCKING_STATUS'] == '1'
return c_async_query(sql, timeout) if ENV['MYSQL_C_ASYNC_QUERY'] == '1'
send_query(sql)
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
get_result

View File

@ -1,13 +1,25 @@
require File.dirname(__FILE__) + '/test_helper'
EventedMysqlTest.new( 10 ) do |test|
EventedMysqlTest.new( 10, "Evented, small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.log_blocking_status = true
test.per_query_overhead = 0.1
test.run!
end
EventedMysqlTest.new( 10 ) do |test|
EventedMysqlTest.new( 10, "Evented, medium overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.c_async_query = true
test.per_query_overhead = 1
test.run!
end
EventedMysqlTest.new( 10, "Evented, large overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 3
test.run!
end
EventedMysqlTest.new( 10, "Evented, random overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = :random
test.run!
end

View File

@ -7,17 +7,20 @@ class MysqlTest
end
attr_accessor :queries,
:context,
:connections,
:connection_signature,
:start,
:done,
:c_async_query,
:log_blocking_status
:per_query_overhead
def initialize( queries )
def initialize( queries, context = '' )
@queries = queries
@context = context
@done = []
@c_async_query = false
@per_query_overhead = 3
yield self if block_given?
end
@ -28,13 +31,18 @@ class MysqlTest
def run!
c_or_native_ruby_async_query do
with_blocking_status do
prepare
yield
end
present_context if context?
prepare
yield
end
end
def per_query_overhead=( overhead )
@per_query_overhead = ( overhead == :random ) ? rand() : overhead
end
protected
def prepare
raise NotImplemented
end
@ -56,27 +64,29 @@ class MysqlTest
def timestamp
Time.now - @start
end
def context?
@context != ''
end
protected
def present_context
log "#############################################"
log "# #{@context}"
log "#############################################"
end
def c_or_native_ruby_async_query
if @c_async_query
ENV['MYSQL_C_ASYNC_QUERY'] = '1'
log "** using C based async_query"
else
ENV['MYSQL_C_ASYNC_QUERY'] = '0'
log "** using native Ruby async_query"
end
yield
end
def with_blocking_status
if @log_blocking_status
ENV['MYSQL_BLOCKING_STATUS'] = '1'
else
ENV['MYSQL_BLOCKING_STATUS'] = '0'
end
yield
def c_or_native_async_query( connection, sql, timeout = nil )
method = @c_async_query ? :c_async_query : :async_query
connection.send( method, sql, timeout )
end
end
@ -85,10 +95,10 @@ class EventedMysqlTest < MysqlTest
attr_accessor :sockets
def initialize( queries )
def initialize( queries, context = '' )
@sockets = []
@connections = {}
super( queries )
super( queries, context )
end
def setup( &block )
@ -121,9 +131,11 @@ class EventedMysqlTest < MysqlTest
end
end
protected
def prepare
@connections.each_value do |conn|
conn.send_query( "select sleep(3)" )
conn.send_query( "select sleep(#{@per_query_overhead})" )
end
end
@ -132,8 +144,6 @@ class EventedMysqlTest < MysqlTest
throw :END_EVENT_LOOP
end
protected
def done?
@done.size == @queries
end
@ -144,10 +154,10 @@ class ThreadedMysqlTest < MysqlTest
attr_accessor :threads
def initialize( queries )
def initialize( queries, context = '' )
@connections = []
@threads = []
super( queries )
super( queries, context )
end
def setup( &block )
@ -167,6 +177,8 @@ class ThreadedMysqlTest < MysqlTest
end
end
protected
def prepare
with_logging "prepare" do
@queries.times do |conn|
@ -174,7 +186,7 @@ class ThreadedMysqlTest < MysqlTest
log "sending query on connection #{conn}"
@connections[conn].async_query( "select sleep(3)" ).each do |result|
c_or_native_async_query( @connections[conn], "select sleep(#{@per_query_overhead})" ).each do |result|
log "connection #{conn} done"
end

View File

@ -1,13 +1,53 @@
require File.dirname(__FILE__) + '/test_helper'
ThreadedMysqlTest.new( 10 ) do |test|
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.log_blocking_status = true
test.per_query_overhead = 0.1
test.run!
end
ThreadedMysqlTest.new( 10 ) do |test|
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, medium overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 1
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, large overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 3
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, random overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = :random
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, C, small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.1
test.c_async_query = true
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, C, medium overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 1
test.c_async_query = true
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, C, large overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 3
test.c_async_query = true
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, C, random overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = :random
test.c_async_query = true
test.run!
end