JRuby on Rails 与 Ruby on Rails,有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/151595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JRuby on Rails vs. Ruby on Rails, what's difference?
提问by epochwolf
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.
我想尝试 JRuby 和 JRuby on Rails。我无法找到有关 JRuby on Rails 和 Ruby on Rails 之间有何区别的信息。
What's the differences I need to look out for?
我需要注意哪些差异?
回答by user23117
JRuby is the Ruby implementation that runs on a JVM whereas Matz's Ruby is a C implementation.
JRuby 是在 JVM 上运行的 Ruby 实现,而 Matz 的 Ruby 是 C 实现。
Key features to note are:
需要注意的主要特点是:
- JRuby runs on Java VM's and it's either compiled or interpreted down to Java byte code.
- 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.
- JRuby is usually hosted within Java application servers such as Sun's GlassFish or even the Tomcat web server.
- Although you cannot use native Ruby gems with JRuby there are JRuby implementations for most of the popular Ruby libraries.
- JRuby 在 Java VM 上运行,它要么被编译要么被解释为 Java 字节码。
- JRuby 可以与 Java 代码集成。如果您有 Java 类库(.jar 的),您可以通过 JRuby 从 Ruby 代码中引用和使用它们。另一方面,您还可以从 Java 内部调用 JRuby 代码。JRuby 还可以使用 JVM 和应用程序服务器功能。
- JRuby 通常托管在 Java 应用程序服务器中,例如 Sun 的 GlassFish 甚至 Tomcat Web 服务器。
- 尽管您不能在 JRuby 中使用本机 Ruby gem,但是大多数流行的 Ruby 库都有 JRuby 实现。
There are other differences which are listed at the JRuby wiki:
JRuby wiki 中列出了其他差异:
回答by kares
I'm surprised there's a crucial thing missing in all answers to this question, related to GIL.
我很惊讶在这个问题的所有答案中都缺少一个与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.
您应该关心的主要区别 esp。在 web 应用程序中,例如使用 Rails 构建的应用程序是真正的并发(“全局解释器锁”免费)。当两个线程使用 JRuby 运行(例如服务 2 个用户请求)时,它们能够在单个进程中并发运行,而在 MRI 中有 GIL(即使使用 1.9 的本机线程)避免并行执行 Ruby 代码。
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.
对于应用程序开发人员来说,这是在考虑 JRuby 时要记住的第一件事,因为它确实很出色,config.threadsafe!但要求您确保您的代码(和您的 gems 代码)是“真正”线程安全的。
回答by Nic Wise
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.
我可能是错的,但我认为你可以用普通 RoR 无法做到的方式打包 JRuby on Rails 应用程序——看看 Mingle 或类似的。可以在不掉下裤子/打开komono的情况下进行销售。
That said, I'm not familiar enough with RoR packaging, so dont hold me to it :)
也就是说,我对 RoR 包装不够熟悉,所以不要强迫我这样做:)
回答by Michael Neale
mostly it should work the same. in jRoR you can access stuff you wouldn't have in RoR. Usually its mainly a deployment concern.
大多数情况下它应该工作相同。在 jRoR 中,您可以访问在 RoR 中没有的内容。通常它主要是一个部署问题。
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).
但是,如果您的 RoR 应用程序使用没有在 JVM 上运行的等效项的本机库,那可能会很麻烦。然而,大多数库都有一个非本地版本可用(至少是我遇到的流行版本)。
回答by user2057354
There are some great answers here already.
这里已经有一些很好的答案。
eebbesen already covered the basics, and kares (himself!) has told us JRuby has no GIL.
eebbesen 已经涵盖了基础知识,并且 kares(他本人!)告诉我们 JRuby 没有 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.
我将从更实际的角度补充一点,我已经在 Ruby on Rails 上启动了应用程序,然后出于性能原因迁移到 JRuby。
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.
有两个主要的性能优势:在某些情况下,JRuby 比(或曾经)快于 Ruby;第二,缺少 Global Interpreter Lock kares 提到的允许我进行多线程处理,虽然棘手,但解锁了数量级的性能优势.
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.
一个非常大的 Ruby on Rails 应用程序在一个小时内移植并运行,gems 等等。唯一的实际故障是 Java 的正则表达式与 Ruby 的略有不同。这对 JRuby 来说是一个巨大的成就。

