Ruby,Rails:mysql2 gem,有人使用这个gem吗?稳定吗? [英] Ruby, Rails: mysql2 gem, does somebody use this gem? Is it stable?

查看:66
本文介绍了Ruby,Rails:mysql2 gem,有人使用这个gem吗?稳定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了 mysql2 gem .与ruby 1.9和utf8编码(与mysql gem相对)可以很好地工作.

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

但是我有疑问.有人在生产中使用这种宝石吗?那性能测试呢?它比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是对现有mysql宝石的一种更现代的替换,已经有一段时间了.我还听说作者不再支持它,而是建议每个人都使用他的纯红宝石版本,因为它与更多的Ruby实现兼容(但是 慢得多).

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).

mysql gem的第一个问题是它在C中不进行任何类型转换,它为您提供了红宝石字符串,然后您必须将其转换为正确的红宝石类型.在纯红宝石中执行此操作非常慢,并且会在堆上创建最初不需要的对象.众所周知,Ruby的GC是它运行缓慢的主要原因.因此,最好避免使用它,并尽可能在纯C语言中做很多事情.

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.

第二个原因是,它在连接,发送查询和等待响应甚至关闭连接时阻止了 entire ruby​​ VM. mysqlplus绝对可以解决此问题,但据我所知仅用于发送查询.

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旨在解决这些问题,同时保持API非常简单. Eric Wong(Unicorn的作者)贡献了一些很棒的补丁程序,这些补丁程序几乎使所有内容都不阻塞和/或在Ruby中发布了GVL. Mysql2::Result类实现Enumerable,因此,如果您知道如何使用数组,就知道如何使用它.

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.

我现在只知道很少有人在生产中使用它,但是它也在Twitter,WorkingPoint和UserVoice进行评估.

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.

我还与Yehuda进行了交谈,讨论它是Rails 3出厂时的推荐/默认设置.它的一些技术和优化也将很快被带入DataObjects的do_mysql驱动程序中.

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.

ActiveRecord驱动程序目前应该非常稳定.您需要做的就是安装gem,然后将database.yml中的适配器名称更改为mysql2.

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 ;)

这篇关于Ruby,Rails:mysql2 gem,有人使用这个gem吗?稳定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆