Charles Oliver N.:
Shot (Piotr S.) wrote:
What would be the JRubyâ€™s equivalent? In other words:
how would one run such code in parallel properly in JRuby?
Just use threads…see below.
You should strongly consider using Java before using RubyInline,
since it’s going to be easier to maintain, less prone to C’s
various fatalities, just as fast, and trivially callable from
Hm. On one hand, I know a bit of C and almost zero Java, and my
assumption is that in the long run the C solution would be the fastest.
On the other, my gut feeling is that learning Java (and its connections
to JRuby, which, from my quick look at them, are rather intuitive) in
my particular case would be faster and more fun than relearning C with
its VALUE pointers, memory management and MRIâ€™s bindings. On the third,
Iâ€™ve yet to try RubyInline+RubyToC combo, but I guess it either works as
advertised (and then thereâ€™s no C to learn) or it doesnâ€™t (and Iâ€™m back
in C land).
Iâ€™m curious about the â€˜just as fastâ€™ claim above â€“ my research code
ended up being mostly bitwise operations on variable-length integers
(which are lovely to work with in Ruby due to the Fixnum/Bignum
transparent switching). My base class is a glorified Set of Integers
â€“ hence my assumptions that I might be able to learn a small enough
subset of MRI C API to implement what I need via RubyInline in
a relatively short period of time.
I have no idea about JVMâ€™s performance other than the most popular
myths(?) from both sides of the discussion, but the cases that require
the optimisations are the ones that will end up being computed for hours
or even days, so I can at least safely skip any warm-up disadvantage.
Does JVM indeed approach C speed in this type of computations in my
above case (Sets of Integers, long running code)? Iâ€™m just looking
for a ballpark quote, of course â€“ something like â€˜most probably yesâ€™,
â€˜maybeâ€™ or â€˜no way, JVM will be at least X times slowerâ€™.
And if you are really interested in inlining that code, there’s
also a java_inline module I wrote that plugs into RubyInline
Cool! I wasnâ€™t aware of it. If I have the time, I might end up
implementing the bottlenecks in both and then switch on runtime
based on the interpreter. :]
I tried a quick google, but itâ€™s surprisingly hard to find if you donâ€™t
know the right words; if youâ€™re replying anyway â€“ what was the constant
that I can use to differentiate between MRI and JRuby?
(Hm, one of the disadvantages of going with JRuby is that my profiling
knowledge is limited to ruby-prof, but then if I learned ruby-prof on
an afternoon then maybe I can learn the basics of a Java profiler in
I think Ara also released another gem that trivially parallizes using
threads, but the name escapes me. I’m sure it’s under codeforpeople
Ah, right, how could I forget! Itâ€™s threadify.
Also, my crude benchmarks are just in: running an actual, small
â€˜productionâ€™ case with one process took 28m57s on MRI 1.8.6.p287,
12m18s on MRI 1.9.1-preview2 and 9m20s on JRuby 1.1.5. Hmmm.
Thanks a lot for your reply! Itâ€™s much appreciated.