JRuby on Rails vs. Ruby on Rails, what's diffe

2019-03-07 17:43发布

问题:

I'm looking to try out JRuby and JRuby on Rails. I'm having trouble finding information on what's difference between JRuby on Rails and Ruby on Rails.

What's the differences I need to look out for?

回答1:

JRuby is the ruby implementation that runs on a JVM whereas Matz's ruby is a C implementation.

Key features to note are:

  1. Jruby runs on Java VM's and it's either compiled or interpreted down to Java byte code.
  2. JRuby can integrate with Java code. If you have java class libraries (.jar's), you can reference and use them from within ruby code with JRuby. In the other direction you can also call Jruby code from within Java. JRuby can also use the JVM and application server capabilities.
  3. JRuby is usually hosted within Java application servers such as Sun's glassfish or even the Tomcat web server.
  4. Although you cannot use native ruby gems with JRuby there are jruby implementations for most of the popular ruby libraries.

There are other differences which are listed at the jruby wiki:

  • Differences between JRuby and Ruby (MRI)
  • JRuby On Rails


回答2:

I'm surprised there's a crucial thing missing in all answers to this question, related to GIL.

The main difference you should care about esp. in web-applications such as ones built with Rails is true concurrency ("Global Interpreter Lock" free). When two threads are running (e.g. serving 2 user requests) with JRuby they are capable of running concurrently within a single process, while in MRI there's the GIL (even with 1.9's native threads) that avoids executing Ruby code in parallel.

For an application developer this is the first thing to keep in mind while considering JRuby, as it really shines with config.threadsafe! but requires you to make sure your code (and your gems code) to be "truly" thread-safe.



回答3:

I may be wrong, but I think you can package a JRuby on Rails app in a way you can't do with normal RoR - look at Mingle or similar. Makes it possible to sell without dropping your pants / opening the komono.

That said, I'm not familiar enough with RoR packaging, so dont hold me to it :)



回答4:

mostly it should work the same. in jRoR you can access stuff you wouldn't have in RoR. Usually its mainly a deployment concern.

However, if your RoR app uses native libraries that don't have an equivalent that runs on the JVM, that can be a pain. However most libs have a non native version available (at least the popular ones I have come across).