Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use ruby threads or just not use ruby altogether for threading?

I have a choice to develop an app which will rely heavily on threading (up to to 200). I know I can use other Ruby interpreters for threading such as JRuby. But there are 2 things:

1) Jruby doesn't support 1.9 yet, so that is a no. Is there any other non-green thread interpreter that supports at least 1.9 as that is a prerequisite for me if I use Ruby.

2) Even using an interpreter such as Jruby, would I really get decent thread perfomance that I can get in Java? Perhaps I should just use Java for this application.

Note: this isn't an attempt at subjective discussion. It is for advice regarding thread performance only. Also, this isn't Java vs Ruby or anything of that nature. I am newer to Ruby and hoping to clear this up for my own benefit, thanks.

like image 356
Zombies Avatar asked Feb 05 '10 15:02

Zombies


People also ask

How many threads can Ruby handle?

The Ruby interpreter handles the management of the threads and only one or two native thread are created.

Is Ruby multithreaded or single threaded?

The Ruby Interpreter is single threaded, which is to say that several of its methods are not thread safe. In the Rails world, this single-thread has mostly been pushed to the server.

What are Ruby threads?

Multi-threading is the most useful property of Ruby which allows concurrent programming of two or more parts of the program for maximizing the utilization of CPU. Each part of a program is called Thread. So, in other words, threads are lightweight processes within a process.

Is Ruby on Rails multi threaded?

It's not a common production platform among the RoR community. As a result, Eventhough Rails itself is thread-safe since version 2.2, there isn't yet a good multi-threaded server for it on Windows servers. And you get the best results by running it on *nix servers using multi-process/single-threaded concurrency model.


1 Answers

You should really benchmark it.

Are your threads going to be doing a lot of simultaneous computation? Then you'd probably need native threads. But if you are going to be waiting for IO all the time, then maybe Ruby's green threads are fine.

Even with this advice, you should cook up a small test program and see if the straightforward way (just using Ruby 1.9) will work.

like image 92
Adam Goode Avatar answered Sep 19 '22 12:09

Adam Goode