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.
The Ruby interpreter handles the management of the threads and only one or two native thread are created.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With