Native Threads in Ruby 1.9.1, Whats in It for Me

Native threads in Ruby 1.9.1, whats in it for me?

I think the big win, is that C based extensions can release the GIL. So, for example, a MySQL adapter can quite cleanly run long running database queries without blocking up all the other Ruby threads.

Advantages of non-concurrent Ruby Threads in Ruby 1.9?

A lot of other Ruby interpreters (JRuby, Rubinius) don't actually have GILs. Also, MRI 2.0 is going to do away with the GIL as well.

Also, in a lot of cases (such as when waiting for IO) the interpreter does switch to another thread. So while it's not technically multithreading (in the case of MRI/REE as of 1.9), it does get some of the benefits.

What do you mean Ruby on Rails is not thread safe?

Your information is out of date.
It is thread safe as of 2.2.2

Keep in mind Ruby MRI 1.8.x, the most widely used implementation of Ruby uses Green Threads, so with 1.8.x if you create 100 threads they all run on the same CPU. Therefore when hosting Rails websites using MRI, you probably want as many instances of Ruby running as you have CPUS. Stuff like passenger takes care of this for you.

This used to be a big problem for JRuby, because JRuby has Native threads, and juggling processes seems superfluous. Anyway, its sorted out now.

On an aside, Iron Ruby, the .Net Ruby interpreter runs native threads.

Note: Ruby 1.9.1 uses native threads, but there is still a global interpreter lock in place.

Is ruby 1.9 capable of using multiple cores for indexing data in solr?

According to this question and this, it can run on all the cores, as long as the thread frees something called Giant VM Lock.

Since this probably depends on the gems (and thus C-extensions) you're using, I would suggest you to do some testing to check that it's actually using all the cores, and in the case that it's not doing it, maybe move to JRuby, which should use all the cores OOB.

I know that this is not a definitive answer, but I hope it helps you to find out a solution.

Snow Leopard + Ruby 1.9.1 + MySQL Gem = Huge problems

Sean, I see that you are running Ruby 1.9.1 under rvm. I'm having the same problem under the same setup (Snow Leopard, rvm, MySQL 64-bit package). All of the alternate gems (mysqlplus, kwatch-mysql-ruby, etc) fail with the same error.

I would suspect the MySQL install, but everything works like a champ under the system default Ruby. So I wonder if rvm isn't the monkey wrench somehow.

EDIT: I figured it out. I installed rvm before upgrading to Snow Leopard, so my Ruby 1.9.1 install needed to be recompiled. For good measure, I reinstalled rvm from scratch.

Here's what I did:

sudo gem uninstall rvm
rm -rf ~/.gem
sudo gem install rvm
rvm-install
rvm install 1.9.1
rvm 1.9.1
env ARCHFLAGS="-arch x86_64" gem install mysql

(NOTE: You cannot use sudo when installing gems under rvm, because rvm works by modifying $PATH.)

(NOTE: I added /usr/local/mysql/bin to my $PATH so I didn't have to specify any of those awful command-line args when installing the mysql gem.)

The mysql gem installed without a hitch.



Related Topics



Leave a reply



Submit