JRuby on Rails 与 Ruby on Rails,有什么区别?

发布于 2024-07-06 13:20:18 字数 108 浏览 11 评论 0原文

我想尝试一下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

檐上三寸雪 2024-07-13 13:20:19

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)

沐歌 2024-07-13 13:20:18

JRuby 是在 JVM 上运行的 Ruby 实现,而 Matz 的 Ruby 是 C 实现。

需要注意的主要功能是:

  1. JRuby 在 Java VM 上运行,并且它被编译或解释为 Java 字节代码。
  2. JRuby 可以与 Java 代码集成。 如果您有 Java 类库 (.jar),则可以通过 JRuby 从 Ruby 代码中引用和使用它们。 另一方面,您也可以从 Java 内部调用 JRuby 代码。 JRuby 还可以使用 JVM 和应用程序服务器功能。
  3. JRuby 通常托管在 Java 应用程序服务器中,例如 Sun 的 GlassFish 甚至 Tomcat Web 服务器。
  4. 尽管您不能将本机 Ruby gem 与 JRuby 一起使用,但大多数流行的 Ruby 库都有 JRuby 实现。

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:

  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:

み格子的夏天 2024-07-13 13:20:18

我很惊讶这个问题的所有答案都遗漏了与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.

2024-07-13 13:20:18

我可能是错的,但我认为你可以用普通 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 :)

找个人就嫁了吧 2024-07-13 13:20:18

大多数情况下它应该工作相同。 在 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).

怀里藏娇 2024-07-13 13:20:18

这里已经有一些很好的答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文