overcome conflict

This commit is contained in:
Roger Pack 2008-09-24 11:01:14 -06:00
commit f73ba931ef
7 changed files with 96 additions and 65 deletions

View File

@ -1,5 +1,6 @@
require 'mkmf'
if /mswin32/ =~ RUBY_PLATFORM
inc, lib = dir_config('mysql')
exit 1 unless have_library("libmysql")

View File

@ -271,9 +271,12 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
myp->connection = Qtrue;
my_bool was_blocking;
vio_blocking(myp->handler.net.vio, 0, &was_blocking);
myp->blocking = vio_is_blocking( myp->handler.net.vio );
vio_fastsend( myp->handler.net.vio );
myp->query_with_result = Qtrue;
rb_obj_call_init(obj, argc, argv);
@ -786,6 +789,13 @@ static VALUE socket(VALUE obj)
MYSQL* m = GetHandler(obj);
return INT2NUM(m->net.fd);
}
/* socket_type */
static VALUE socket_type(VALUE obj)
{
MYSQL* m = GetHandler(obj);
VALUE description = vio_description( m->net.vio );
return NILorSTRING( description );
}
/* blocking */
static VALUE blocking(VALUE obj){
@ -838,43 +848,35 @@ static VALUE get_result(VALUE obj)
return store_result(obj);
}
static VALUE schedule(VALUE obj, VALUE timeout)
{
MYSQL* m = GetHandler(obj);
fd_set read;
timeout = ( NIL_P(timeout) ? m->net.read_timeout : INT2NUM(timeout) );
struct timeval tv = { tv_sec: timeout, tv_usec: 0 };
FD_ZERO(&read);
FD_SET(m->net.fd, &read);
if (rb_thread_select(m->net.fd + 1, &read, NULL, NULL, &tv) < 0) {
rb_raise(eMysql, "query: timeout");
}
}
/* async_query(sql,timeout=nil) */
static VALUE async_query(int argc, VALUE* argv, VALUE obj)
{
MYSQL* m = GetHandler(obj);
VALUE sql, timeout;
fd_set read;
int ret;
rb_scan_args(argc, argv, "11", &sql, &timeout);
send_query(obj,sql);
if (NIL_P(timeout)) {
timeout = m->net.read_timeout;
}
VALUE args[1];
args[0] = timeout;
struct timeval tv = { tv_sec: timeout, tv_usec: 0 };
for(;;) {
FD_ZERO(&read);
FD_SET(m->net.fd, &read);
ret = rb_thread_select(m->net.fd + 1, &read, NULL, NULL, &tv);
if (ret < 0) {
rb_sys_fail(0);
}
if (ret == 0) {
continue;
}
if (readable(1, (VALUE *)args, obj) == Qtrue) {
break;
}
}
schedule(obj, timeout);
return get_result(obj);
}
@ -2172,6 +2174,7 @@ void Init_mysql(void)
rb_define_method(cMysql, "readable?", readable, -1);
rb_define_method(cMysql, "blocking?", blocking, 0);
rb_define_method(cMysql, "socket", socket, 0);
rb_define_method(cMysql, "socket_type", socket_type, 0);
rb_define_method(cMysql, "refresh", refresh, 1);
rb_define_method(cMysql, "reload", reload, 0);
rb_define_method(cMysql, "select_db", select_db, 1);

View File

@ -15,7 +15,8 @@ Gem::Specification.new do |s|
"Rakefile",
"lib/mysqlplus.rb",
"test/test_helper.rb",
"test/threaded_test.rb",
"test/native_threaded_test.rb",
"test/c_threaded_test.rb",
"test/evented_test.rb",
"ext/error_const.h",
"ext/extconf.rb",

36
test/c_threaded_test.rb Normal file
View File

@ -0,0 +1,36 @@
require File.dirname(__FILE__) + '/test_helper'
ThreadedMysqlTest.new( 10, "Threaded, C, very small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.005
test.query_with = :c_async_query
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.query_with = :c_async_query
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.query_with = :c_async_query
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.query_with = :c_async_query
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.query_with = :c_async_query
test.run!
end

View File

@ -1,5 +1,11 @@
require File.dirname(__FILE__) + '/test_helper'
EventedMysqlTest.new( 10, "Evented, very small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.005
test.run!
end
EventedMysqlTest.new( 10, "Evented, small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.1

View File

@ -1,53 +1,36 @@
require File.dirname(__FILE__) + '/test_helper'
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, very small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.005
test.query_with = :async_query
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.1
test.query_with = :async_query
test.run!
end
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, medium overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 1
test.query_with = :async_query
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.query_with = :async_query
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.query_with = :async_query
test.run!
end

View File

@ -12,15 +12,17 @@ class MysqlTest
:connection_signature,
:start,
:done,
:c_async_query,
:per_query_overhead
:query_with,
:per_query_overhead,
:timeout
def initialize( queries, context = '' )
@queries = queries
@context = context
@done = []
@c_async_query = false
@query_with = :async_query
@per_query_overhead = 3
@timeout = 20
yield self if block_given?
end
@ -76,7 +78,7 @@ class MysqlTest
end
def c_or_native_ruby_async_query
if @c_async_query
if @query_with == :c_async_query
log "** using C based async_query"
else
log "** using native Ruby async_query"
@ -84,9 +86,8 @@ class MysqlTest
yield
end
def c_or_native_async_query( connection, sql, timeout = nil )
method = @c_async_query ? :c_async_query : :async_query
connection.send( method, sql, timeout )
def dispatch_query( connection, sql, timeout = nil )
connection.send( @query_with, sql, timeout )
end
end
@ -186,7 +187,7 @@ class ThreadedMysqlTest < MysqlTest
log "sending query on connection #{conn}"
c_or_native_async_query( @connections[conn], "select sleep(#{@per_query_overhead})" ).each do |result|
dispatch_query( @connections[conn], "select sleep(#{@per_query_overhead})", @timeout ).each do |result|
log "connection #{conn} done"
end