JRuby on Rails vs. Ruby on Rails, what's difference?
Asked Answered
F

6

139

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?

Formate answered 30/9, 2008 at 3:0 Comment(0)
A
164

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:

Anzovin answered 30/9, 2008 at 4:13 Comment(4)
Thank you, that answers just about everything I was looking for. :)Formate
oh, and it runs a bit slower than 1.9Voronezh
To see performance differences in JRuby on Rails, it's recommended to have a multicored machine with sufficient resources. Slow database queries can also bottleneck JRuby and cause it to perform similar or slower than MRI on Rails. JRuby also uses significantly more upfront memory than MRI.Fortin
We have both massive performance with using jruby with Oracle over VPN (tests run incredibly slowly) and also locally (no VPN) just starting up ruby, rails console, etc takes 30 seconds+ instead of 3.Manumit
B
63

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.

Buffer answered 29/6, 2012 at 7:52 Comment(0)
R
7

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 :)

Realistic answered 7/10, 2008 at 14:42 Comment(1)
You're absolutely correct on this, though you'll need something like the Rawr or Roir gem to do this completely (last time I used Mingle, it had un-obfuscated Ruby files...).Lichi
G
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).

Graubert answered 30/9, 2008 at 3:53 Comment(0)
T
2

There are some great answers here already.

eebbesen already covered the basics, and kares (himself!) has told us JRuby has no GIL.

I'll add from a more practical perspective, I've launched apps on Ruby on Rails, and then migrated to JRuby for performance reasons.

There were two main performance benefits: JRuby is (or was) simply faster than Ruby in some circumstances, and two, the lack of the Global Interpreter Lock kares mentions allowed me to do multithreading, which, while tricky, unlocked orders of magnitude performance benefits.

A very large Ruby on Rails app ported and ran in an hour, gems and all. The only actual glitch was that Java's regexes are slightly different than Ruby's. That's a monumental achievement on JRuby's part.

Tush answered 16/12, 2019 at 15:59 Comment(0)
C
0

The main difference between JRuby and regular Ruby programming language is that JRuby uses a Java Virtual Machine (JVM) instead of a traditional Ruby virtual machine. This allows JRuby to run on any platform that supports the Java Runtime Environment. This can include Windows, Mac, Linux and other platforms that support Java.

JRuby has some unique benefits because it seamlessly integrates with all existing Java libraries and other technologies, which can be a great advantage in certain cases Like Threading. It is also faster in certain cases as well.

But all depends on your project if you have JAVA backend/Lots of threading requirements then Jruby is good else go for Ruby. (Notes: Ruby have better support than JRUBY)

Comprehensible answered 26/2 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.