开发者

How to get decent MySQL driver perfomance in Ruby

开发者 https://www.devze.com 2022-12-23 20:03 出处:网络
I notice that I am getting very poor performance for either or both inserts and queries. The queries themselves are basic and can execute with no delay directly from mysql. The ruby script that I wrot

I notice that I am getting very poor performance for either or both inserts and queries. The queries themselves are basic and can execute with no delay directly from mysql. The ruby script that I wrote is only 1 thread, so only 1 connection is being used, and never closed unless the script is terminated. Pretty basic, I am just trying to insert a lot of rows. There is a look-up or two to get a surrogate key, or to check for duplicates, but the complexity is just O(n). Also, it isn't like there are millions of records, so again the queries themselves take no time to run.

I am using:

  • Ruby 1.9.1
  • Gem/driver: ruby-mysql 2.9.2
  • MySQL 5.1.37-1ubuntu5.1
  • ^ all 32 bit versions on a 32bit ubuntu distro

I am getting about 1-2 inserts per second, pretty slow. I know a lot of people will suggest to change drivers, but that means I have some refactoring and retesting to do. So I would really appreciate any help, but please if you do recomend that at least say why you do... EG: if you have 开发者_Go百科used ruby-mysql x.x.x before and found another mysql driver to be better as opposed to the obligatory, "change drivers".

What I would like to know:

  1. How can I improve performance with ruby-mysql 2.9.2
  2. If and only if I cannot do this with ruby-mysql 2.9.2, what should I do?
  3. If I made the script create new threads for DB insertions then I could speed up performance... is this what I need to do?


Don't use the pure-ruby mysql gem. It's notorious for performing slowly. Use the one with the compiled client.

$ gem install mysql

You'll need a working build environment and the ruby development libraries too.

I'm pretty sure the interface/API is the same, or very similar.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号