JRuby on Rails 与 Ruby on Rails,有什么区别?
我想尝试一下 JRuby 和 JRuby on Rails。 我无法找到有关 JRuby on Rails 和 Ruby on Rails 之间差异的信息。
我需要注意哪些差异?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
JRuby 和常规 Ruby 编程语言之间的主要区别在于 JRuby 使用 Java 虚拟机 (JVM) 而不是传统的 Ruby 虚拟机。 这使得 JRuby 可以在任何支持 Java 运行时环境的平台上运行。 这可以包括 Windows、Mac、Linux 和其他支持 Java 的平台。
JRuby 具有一些独特的优势,因为它与所有现有的 Java 库和其他技术无缝集成,这在某些情况下(例如线程)可能是一个很大的优势。 在某些情况下它也更快。
但一切都取决于您的项目,如果您有 JAVA 后端/大量线程需求,那么 Jruby 很好,否则就选择 Ruby。 (注:Ruby比JRUBY有更好的支持)
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)
JRuby 是在 JVM 上运行的 Ruby 实现,而 Matz 的 Ruby 是 C 实现。
需要注意的主要功能是:
JRuby wiki 中列出了其他差异:
JRuby is the Ruby implementation that runs on a JVM whereas Matz's Ruby is a C implementation.
Key features to note are:
There are other differences which are listed at the JRuby wiki:
我很惊讶这个问题的所有答案都遗漏了与GIL相关的重要内容。
您应该关心的主要区别是。 在 Web 应用程序(例如使用 Rails 构建的应用程序)中,它是真正的并发(“全局解释器锁”免费)。 当使用 JRuby 运行两个线程(例如,服务 2 个用户请求)时,它们能够在单个进程中同时运行,而在 MRI 中,有 GIL(即使使用 1.9 的本机线程)可以避免并行执行 Ruby 代码。
对于应用程序开发人员来说,这是在考虑 JRuby 时要记住的第一件事,因为它确实在
config.threadsafe!
中大放异彩,但要求您确保您的代码(以及您的 gems 代码)是“真正”线程安全。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.我可能是错的,但我认为你可以用普通 RoR 无法做到的方式打包 JRuby on Rails 应用程序 - 看看 Mingle 或类似的。 可以在不脱裤子/打开菰的情况下进行销售。
也就是说,我对 RoR 封装还不够熟悉,所以不要让我坚持:)
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 :)
大多数情况下它应该工作相同。 在 jRoR 中,您可以访问 RoR 中没有的内容。 通常主要是部署问题。
但是,如果您的 RoR 应用程序使用的本机库没有在 JVM 上运行的等效库,那么这可能会很痛苦。 然而,大多数库都有一个非本机版本可用(至少是我遇到过的流行版本)。
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).
这里已经有一些很好的答案。
eebbesen 已经介绍了基础知识,并且 kares(他自己!)告诉我们 JRuby 没有 GIL。
我将从更实际的角度补充一下,我在 Ruby on Rails 上启动了应用程序,然后出于性能原因迁移到 JRuby。
主要有两个性能优势:在某些情况下,JRuby(或曾经)比 Ruby 更快,其次,缺少卡雷斯提到的全局解释器锁,使我能够进行多线程处理,这虽然很棘手,但解锁了数量级的性能优势。
一个非常大的 Ruby on Rails 应用程序在一个小时内移植并运行,包括宝石等等。 唯一实际的问题是 Java 的正则表达式与 Ruby 的略有不同。 对于 JRuby 来说,这是一项巨大的成就。
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.