Skip to content

Instantly share code, notes, and snippets.

@deepak
Created April 5, 2010 11:20
Show Gist options
  • Save deepak/356250 to your computer and use it in GitHub Desktop.
Save deepak/356250 to your computer and use it in GitHub Desktop.
mysql blocks the ruby interpreter
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