Created
April 5, 2010 11:20
-
-
Save deepak/356250 to your computer and use it in GitHub Desktop.
mysql blocks the ruby interpreter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mysql' | |
# thanks to piyush_ in irc. | |
# mysql blocks the ruby interpreter | |
# alternatives: | |
# 1) use neverblock/mysqlplus mysql driver. | |
# 2) use jruby - will use java threads. | |
# 3) postgres driver does not block. | |
# 4) the ruby mysql lib uses threads so does not block but is slower and threading generally sucks in ruby. | |
# 5) check if there is a async mysql driver and a ruby binding to it. | |
# deployment: | |
# effect of threadpool like in ActiveRecord on this. | |
# mongrel_cluster will have seperate ruby instances what about passenger? | |
# using drb or like to seperate it out of the ruby interpreter. | |
# see http://gist.github.com/356462 for do_mysql | |
thread1 = Thread.new { | |
while(true) do | |
print '*' | |
sleep 1 | |
end | |
} | |
my = Mysql.connect('localhost', 'root', 'deepak123', 'railsdb') | |
puts "=== started blocking ===" | |
stmt = my.prepare "select sleep(10)" | |
stmt.execute | |
puts "=== finished blocking ===" | |
thread1.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment