简体   繁体   中英

Ruby, Rails: mysql2 gem, does somebody use this gem? Is it stable?

I found mysql2 gem . It works fine with ruby 1.9 and utf8 encoding (as opposed to mysql gem).

But I have doubts. Does somebody use this gem in production? What about the performance test? Is it faster than mysql gem? Is it stable?

mysql2 is meant as a more modern replacement for the existing mysql gem, which has been stale for a while now. I also heard that the author isn't supporting it anymore and instead recommends everyone use his pure-ruby version since it's compatible with more Ruby implementations (but is much slower).

The first issue with the mysql gem is it doesn't do any type casting in C, it gives you back ruby strings which you then have to convert into proper ruby types. Doing that in pure-ruby is extremely slow, and creates objects on the heap that never needed to existing in the first place. And as we all know, Ruby's GC is it's primary reason for it's slowness. So it's best to avoid it and do as much in pure C as you can.

Second is that it blocks the entire ruby VM while connecting, sending queries and waiting for responses, and even closing the connection. mysqlplus definitely helps with this issue, but only for sending queries as far as I know.

mysql2 aims to solve these problems while keeping the API extremely simple. Eric Wong (author of Unicorn) has contributed some awesome patches that make nearly everything non-blocking and/or release the GVL in Ruby. The Mysql2::Result class implements Enumerable so if you know how to use an Array, you know how to use it.

I'm only aware of a few people using it in production right now but it is being evaluated at Twitter, WorkingPoint and UserVoice too.

I'm also in talks with Yehuda about it being the recommended/default for Rails 3 when it ships. Some of its techniques and optimizations are also going to be brought into DataObjects' do_mysql driver soon as well.

The ActiveRecord driver should be pretty solid at the moment. All you should need to do is have the gem installed, and change your adapter name in database.yml to mysql2 .

If you're interested in using it, give it a try. I'm quick to push fixes if you find any issues ;)

mysql2现在是Rails 3中的默认设置

有点晚了-但是我在几个站点的生产环境中使用了mysql2,并且发现它非常稳定,因为几周前解决了一些关闭连接的问题。

如果有人想在Windows的Rails 3.0.0中使用mysql gem而不是mysql2 gem,我写了一篇简短的文章,解释了如何调整Rails应用程序生成器

Make sure you convert your 'latin1' characters to 'utf8', following the answer here:

UTF8 MySQL problems on Rails - encoding issues with utf8_general_ci

FYI, When using mysql2 (0.2.x) with Rails 3.0.11 I had to downgrade my version of RubyGems from 1.8.15 to 1.8.10. Otherwise Passenger barfs...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM