Permalink
Browse files

overcome conflict

  • Loading branch information...
2 parents 02e2650 + c17d4b6 commit f73ba931ef8301313b037cd19612cb72edfa012a Roger Pack committed Sep 24, 2008
Showing with 96 additions and 65 deletions.
  1. +1 −0 ext/extconf.rb
  2. +31 −28 ext/mysql.c
  3. +2 −1 mysqlplus.gemspec
  4. +36 −0 test/c_threaded_test.rb
  5. +6 −0 test/evented_test.rb
  6. +11 −28 test/{threaded_test.rb → native_threaded_test.rb}
  7. +9 −8 test/test_helper.rb
View
@@ -1,5 +1,6 @@
require 'mkmf'
+
if /mswin32/ =~ RUBY_PLATFORM
inc, lib = dir_config('mysql')
exit 1 unless have_library("libmysql")
View
@@ -269,11 +269,14 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
myp->handler.reconnect = 0;
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
@@ -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",
View
@@ -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
@@ -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
@@ -1,53 +1,36 @@
require File.dirname(__FILE__) + '/test_helper'
-ThreadedMysqlTest.new( 10, "Threaded, native Ruby, small overhead" ) do |test|
- test.setup{ Mysql.real_connect('localhost','root') }
- test.per_query_overhead = 0.1
- 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.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|
+ThreadedMysqlTest.new( 10, "Threaded, native Ruby, very small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
- test.per_query_overhead = :random
+ test.per_query_overhead = 0.005
+ test.query_with = :async_query
test.run!
end
-ThreadedMysqlTest.new( 10, "Threaded, C, small overhead" ) do |test|
+ThreadedMysqlTest.new( 10, "Threaded, native Ruby, small overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.1
- test.c_async_query = true
+ test.query_with = :async_query
test.run!
end
-ThreadedMysqlTest.new( 10, "Threaded, C, medium overhead" ) 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.c_async_query = true
+ test.query_with = :async_query
test.run!
end
-ThreadedMysqlTest.new( 10, "Threaded, C, large overhead" ) do |test|
+ThreadedMysqlTest.new( 10, "Threaded, native Ruby, large overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 3
- test.c_async_query = true
+ test.query_with = :async_query
test.run!
end
-ThreadedMysqlTest.new( 10, "Threaded, C, random overhead" ) do |test|
+ThreadedMysqlTest.new( 10, "Threaded, native Ruby, 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
@@ -12,15 +12,17 @@ class NotImplemented < StandardError
: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,17 +78,16 @@ def present_context
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"
end
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 @@ def prepare
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

0 comments on commit f73ba93

Please sign in to comment.