how to use mysqlplus adapter with rails 2.2 [without fibers]

NeverBlock provides a way to use fibers and rails and…never block.

It is also possible to use a NeverBlock spin off [mysqlplus] to be used in a threaded rails project (thus allowing you to have non blocking IO in the threaded realm, i.e. allowing rails to be true multi-threaded, once that happens with rails 2.2).

Here’s how:
setup an edge rails project [1] [or use rails 2.2]
install mysqlplus
copy https://github.com/methodmissing/mysqlplus_adapter/tree library to the vendor/plugins directory
change your database.yml entries say mysqlplus instead of mysql
add pool: 4 to the database.yml entries [from [2]]
within environment.rb add
config.threadsafe! # from [3]

edit rails.rb within the mongrel gem and comment out any time it uses synchronize [since it's not thread ready]
ex on my machine:
vi ~/dev/ruby_186_installed/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb
@guard.synchronize {
stuff
}
becomes
#@guard.synchronize
stuff
#}

then script/server should work in a multi-threaded way. Test by creating an action that is ActiveRecord::Base.connection.execute(“select sleep(1)”) and run two simultaneously requests–they should both come back in 1s.

Now if only rails 2.2 can come out… :)

[1] http://betterlogic.com/roger/?p=464
[2] http://groups.google.com/group/rubyonrails-core/browse_thread/thread/ab6ecc43f7c0f462/fa4f1fc1cbe3b09e?lnk=gst&q=pool#fa4f1fc1cbe3b09e
[3] http://www.infoq.com/news/2008/08/rails-threadsafe-etags-support

5 thoughts on “how to use mysqlplus adapter with rails 2.2 [without fibers]

  1. Hey, now that Rails 2.2 is out, I’d love to hear more about your experiences using this. Can you convince us that there’s no risk posed by editing mongrel/rails.rb? Are you using it in production under any significant load?

    I’d also love to see benchmarks comparing:
    * Rails 2.2
    * Rails 2.2 with MySQLplus
    * Rails 2.1 with MySQLplus
    * Rails 2.1

  2. I did do some test with neverblock [which uses fibers+mysqlplus] and 1.8.6–because of the “poor man’s fibers” used it wasn’t as fast as normal threaded, at least until you started having mysql queries that were very long.

    You bring up an interesting, point though–is this useful?
    Metrics are probably best.
    For those who have “high concurrency” I’d “imagine” 1.9 + neverblock is fastest.
    For those with “low concurrency, high DB wait” I’d imagine mysqlplus [or neverblock] would be faster. Hmm.

  3. Hi Roger,

    I am a 2.2 beginner and I am searching for a way to install 2.2 on Leopard without installing the Compiler and stuff. Do I understand this correctly, this (above) works without compiling the mysql-adapter? Or do you know any way to install the (any) MySQL adapter with 2.2 that works without building/installing?

    Thanks, Tom

  4. unfortunately I think you’ll need to install gcc and the mysql devel stuffs [which might come preinstalled anyway]. I don’t think mac really has a system of pre-built binaries, and even if it did, this stuff is too new to probably be in there already :)

    If I were you I’d install macports [you can even install it locally to a subdirectory to your home, if I remember correctly] and then install gcc through it or what not.
    Good luck!
    -=R

Leave a Reply

Your email address will not be published. Required fields are marked *


five × = 15

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>