Merge branch 'master' of git@github.com:oldmoe/mysqlplus
This commit is contained in:
commit
6c2b9ecb84
@ -31,6 +31,10 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
|
||||||
|
flags << "-DHAVE_TBR"
|
||||||
|
end
|
||||||
|
|
||||||
# make mysql constant
|
# make mysql constant
|
||||||
File.open("conftest.c", "w") do |f|
|
File.open("conftest.c", "w") do |f|
|
||||||
f.puts src
|
f.puts src
|
||||||
|
@ -2141,7 +2141,7 @@ void Init_mysql(void)
|
|||||||
#endif
|
#endif
|
||||||
rb_define_method(cMysql, "query", query, 1);
|
rb_define_method(cMysql, "query", query, 1);
|
||||||
rb_define_method(cMysql, "real_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, "send_query", send_query, 1);
|
||||||
rb_define_method(cMysql, "get_result", get_result, 0);
|
rb_define_method(cMysql, "get_result", get_result, 0);
|
||||||
rb_define_method(cMysql, "readable?", readable, -1);
|
rb_define_method(cMysql, "readable?", readable, -1);
|
||||||
|
@ -2,11 +2,7 @@ require 'mysql'
|
|||||||
|
|
||||||
class Mysql
|
class Mysql
|
||||||
|
|
||||||
alias_method :c_async_query, :async_query
|
|
||||||
|
|
||||||
def async_query(sql, timeout = nil)
|
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)
|
send_query(sql)
|
||||||
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
||||||
get_result
|
get_result
|
||||||
|
@ -1,13 +1,25 @@
|
|||||||
require File.dirname(__FILE__) + '/test_helper'
|
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.setup{ Mysql.real_connect('localhost','root') }
|
||||||
test.log_blocking_status = true
|
test.per_query_overhead = 0.1
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
||||||
|
|
||||||
EventedMysqlTest.new( 10 ) do |test|
|
EventedMysqlTest.new( 10, "Evented, medium overhead" ) do |test|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
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!
|
test.run!
|
||||||
end
|
end
|
@ -7,17 +7,20 @@ class MysqlTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :queries,
|
attr_accessor :queries,
|
||||||
|
:context,
|
||||||
:connections,
|
:connections,
|
||||||
:connection_signature,
|
:connection_signature,
|
||||||
:start,
|
:start,
|
||||||
:done,
|
:done,
|
||||||
:c_async_query,
|
:c_async_query,
|
||||||
:log_blocking_status
|
:per_query_overhead
|
||||||
|
|
||||||
def initialize( queries )
|
def initialize( queries, context = '' )
|
||||||
@queries = queries
|
@queries = queries
|
||||||
|
@context = context
|
||||||
@done = []
|
@done = []
|
||||||
@c_async_query = false
|
@c_async_query = false
|
||||||
|
@per_query_overhead = 3
|
||||||
yield self if block_given?
|
yield self if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -28,13 +31,18 @@ class MysqlTest
|
|||||||
|
|
||||||
def run!
|
def run!
|
||||||
c_or_native_ruby_async_query do
|
c_or_native_ruby_async_query do
|
||||||
with_blocking_status do
|
present_context if context?
|
||||||
prepare
|
prepare
|
||||||
yield
|
yield
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def per_query_overhead=( overhead )
|
||||||
|
@per_query_overhead = ( overhead == :random ) ? rand() : overhead
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
def prepare
|
def prepare
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
end
|
end
|
||||||
@ -57,26 +65,28 @@ class MysqlTest
|
|||||||
Time.now - @start
|
Time.now - @start
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
def context?
|
||||||
|
@context != ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def present_context
|
||||||
|
log "#############################################"
|
||||||
|
log "# #{@context}"
|
||||||
|
log "#############################################"
|
||||||
|
end
|
||||||
|
|
||||||
def c_or_native_ruby_async_query
|
def c_or_native_ruby_async_query
|
||||||
if @c_async_query
|
if @c_async_query
|
||||||
ENV['MYSQL_C_ASYNC_QUERY'] = '1'
|
|
||||||
log "** using C based async_query"
|
log "** using C based async_query"
|
||||||
else
|
else
|
||||||
ENV['MYSQL_C_ASYNC_QUERY'] = '0'
|
|
||||||
log "** using native Ruby async_query"
|
log "** using native Ruby async_query"
|
||||||
end
|
end
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_blocking_status
|
def c_or_native_async_query( connection, sql, timeout = nil )
|
||||||
if @log_blocking_status
|
method = @c_async_query ? :c_async_query : :async_query
|
||||||
ENV['MYSQL_BLOCKING_STATUS'] = '1'
|
connection.send( method, sql, timeout )
|
||||||
else
|
|
||||||
ENV['MYSQL_BLOCKING_STATUS'] = '0'
|
|
||||||
end
|
|
||||||
yield
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -85,10 +95,10 @@ class EventedMysqlTest < MysqlTest
|
|||||||
|
|
||||||
attr_accessor :sockets
|
attr_accessor :sockets
|
||||||
|
|
||||||
def initialize( queries )
|
def initialize( queries, context = '' )
|
||||||
@sockets = []
|
@sockets = []
|
||||||
@connections = {}
|
@connections = {}
|
||||||
super( queries )
|
super( queries, context )
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup( &block )
|
def setup( &block )
|
||||||
@ -121,9 +131,11 @@ class EventedMysqlTest < MysqlTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
def prepare
|
def prepare
|
||||||
@connections.each_value do |conn|
|
@connections.each_value do |conn|
|
||||||
conn.send_query( "select sleep(3)" )
|
conn.send_query( "select sleep(#{@per_query_overhead})" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -132,8 +144,6 @@ class EventedMysqlTest < MysqlTest
|
|||||||
throw :END_EVENT_LOOP
|
throw :END_EVENT_LOOP
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def done?
|
def done?
|
||||||
@done.size == @queries
|
@done.size == @queries
|
||||||
end
|
end
|
||||||
@ -144,10 +154,10 @@ class ThreadedMysqlTest < MysqlTest
|
|||||||
|
|
||||||
attr_accessor :threads
|
attr_accessor :threads
|
||||||
|
|
||||||
def initialize( queries )
|
def initialize( queries, context = '' )
|
||||||
@connections = []
|
@connections = []
|
||||||
@threads = []
|
@threads = []
|
||||||
super( queries )
|
super( queries, context )
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup( &block )
|
def setup( &block )
|
||||||
@ -167,6 +177,8 @@ class ThreadedMysqlTest < MysqlTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
def prepare
|
def prepare
|
||||||
with_logging "prepare" do
|
with_logging "prepare" do
|
||||||
@queries.times do |conn|
|
@queries.times do |conn|
|
||||||
@ -174,7 +186,7 @@ class ThreadedMysqlTest < MysqlTest
|
|||||||
|
|
||||||
log "sending query on connection #{conn}"
|
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"
|
log "connection #{conn} done"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,13 +1,53 @@
|
|||||||
require File.dirname(__FILE__) + '/test_helper'
|
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.setup{ Mysql.real_connect('localhost','root') }
|
||||||
test.log_blocking_status = true
|
test.per_query_overhead = 0.1
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
||||||
|
|
||||||
ThreadedMysqlTest.new( 10 ) do |test|
|
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, medium overhead" ) do |test|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
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.c_async_query = true
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user