El Jueves, 17 de Diciembre de 2009, Aman Gupta escribió:
> The mysql driver blocks, you have to use the mysqlplus driver and also
> enable async queries:
>
> require 'mysqlplus'
> class Mysql; alias :query :async_query; end
Thanks a lot. I've coded an example which shows the advantage of 'mysqlplus'
in an easy way to understand the difference:
mysql_vs_mysqlplus.rb
-------------------------------------------------
#!/usr/bin/env ruby
# Run "./mysql_vs_mysqlplus.rb" to use "mysql".
# Run "./mysql_vs_mysqlplus.rb plus" to use "mysqlplus".
case ARGV[0]
when nil
puts "Using 'mysql'"
require "mysql"
else
puts "Using 'mysqlplus'"
require "mysqlplus"
class Mysql; alias :query :async_query; end
end
DB = Mysql.real_connect("localhost", "user", "passwd", "database")
def slow_sql_query
printf "[['slow_sql_query' started]]"
DB.query("SELECT sleep(3)")
printf "[['slow_sql_query' ended]]"
end
def looping
loop do
printf "."
sleep 0.1
end
end
t1 = Thread.new do
looping
end
t2 = Thread.new do
sleep 1
slow_sql_query
end
t1.join
t2.join
-------------------------------------------------
Using "mysql" Ruby gets blocked for 3 seconds when performing the "slow" SQL
query.
Using "mysqlplus" the SQL query doesn't block !!
:)
Thanks a lot for all you help.
--
Iñaki Baz Castillo <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.