开发 RoR 应用程序后,我需要了解有关 JRuby on Rails 的哪些信息?

发布于 2024-09-16 15:49:09 字数 371 浏览 8 评论 0原文

我使用 Ruby on Rails 完成了一些项目。我将使用 JRuby on Rails 并将其托管在 GAE 上。那么在开发 JRuby 应用程序时我需要了解哪些内容。我读到

  • JRuby 具有相同的语法
  • ,我可以访问 Java 库
  • JRuby 无法访问某些 gem/插件
  • JRuby 应用程序第一次需要一些时间才能加载,所以我必须通过发送来保持它的活动 每 5 分钟左右请求一次
  • 我不能使用 ActiveRecord,而是必须使用 DataMapper

如果我所做的任何陈述有误,请更正,还有其他我必须知道的吗?我是否需要从头开始阅读 JRuby,还是可以像往常一样开发 Ruby 应用程序?

I have done a few projects using Ruby on Rails. I am going to use JRuby on Rails and hosting it on GAE. In that case what are the stuff that I need to know while developing JRuby apps. I read that

  • JRuby has the same syntax
  • I can access Java libraries
  • JRuby does not have access to some gems/plugins
  • JRuby app would take some time to load for the first time, so I have to keep it alive by sending
    request every 5 mins or so
  • I cannot use ActiveRecord and instead I must DataMapper

Please correct if I am wrong about any of the statements I have made and Is there anything else that I must know?. Do I need to start reading about JRuby from the scratch or I can go about as usual developing Ruby apps?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

晚雾 2024-09-23 15:49:09

我每天都使用 JRuby。

正确:

  • JRuby 具有相同的语法
  • JRuby 无法访问某些 gem/插件
  • 我可以访问 Java 库

有些 gem/插件具有特定于 jruby 的版本,有些根本不起作用。总的来说,我发现的问题很少,并且随着库和平台的成熟,很多问题都消失了(JRuby 已经变得更好了)。

您可以访问 Java,但一般来说您为什么要这样做?

错误:

  • JRuby 应用程序首次加载需要一些时间,因此我必须通过每 5 分钟左右发送一次请求来保持它的活动状态,因此
  • 我不能使用 ActiveRecord,而必须使用 DataMapper,

尽管我猜是这样可以想象一个服务器设置,其中 JVM 的初始启动/预热成本意味着您需要 ping 服务器,JRuby 中没有任何固有的东西可以实现这一点。如果您需要保持服务器处于活动状态,您应该查看您的部署环境。与乘客共享托管时也会发生类似的情况,应用程序在一段时间不活动后可能会出现内存不足的情况。

另外,我们使用 ActiveRecord 也没有任何问题。

I use JRuby everyday.

True:

  • JRuby has the same syntax
  • JRuby does not have access to some gems/plugins
  • I can access Java libraries

Some gems/plugins have jruby-specific versions, some don't work at all. In general, I have found few problems and as the libraries and platforms have matured a lot of the problems have gone away (JRuby has become a lot better).

You can access Java, but in general why would you want to?

False:

  • JRuby app would take some time to load for the first time, so I have to keep it alive by sending request every 5 mins or so
  • I cannot use ActiveRecord and instead I must DataMapper

Although I guess it is possible to imagine a server setup where the initial startup/warmup cost of the JVM means you need to ping the server, there is nothing inherent in JRuby that makes this true. If you need to keep the server alive, you should look at your deployment environment. Something similar happens in shared-hosting with passenger where an app can go out of memory after a period of inactivity.

Also, we use ActiveRecord with no problems at all.

一抹微笑 2024-09-23 15:49:09

据我所知,rails 3 与 jruby 100% 兼容,因此该路径上应该没有问题。

与每个新平台一样,您应该通过使用 jruby 让自己适应它。我建议使用 RVM 来做到这一点。

就您的问题而言:

  • JRuby 只是像 MRI 或 Rubinus 一样的其他运行时
  • ,因为 JRuby 在 JVM 中,使用 Java 非常容易,但您也可以使用 MRI 中的 RJB,
  • 当它们使用本机 C 库时,某些 gem 不兼容,不在 JRuby 上运行的
  • JVM 和您的应用程序容器需​​要启动时间和一些时间来加载您的应用程序,但仅此而已,不需要保持活动状态,这是错误的,
  • 您可以使用任何您想要的东西,大多数 gems 都已更新与 JRuby 兼容

afaik, rails 3 is 100% compatible with jruby, so there should be no problem on that path.

like every new platform, you should make yourself comfortable with it by playing around with jruby. i recommend using RVM to do that.

as far as you questions go:

  • JRuby is just an other runtime like MRI or Rubinus
  • since JRuby is within the JVM using Java is very easy, but you can also use RJB from MRI
  • some gems are not compatible, when they use native c libraries, that do not run on JRuby
  • the JVM and your application container need startup time and some time to load your app, but that is all, there is no need for keep alive, that is wrong
  • you can use whatever you want, most gems are updated to be compatible with JRuby
柳若烟 2024-09-23 15:49:09

@TobyHede 主要涵盖了您认为可能遇到的问题,所以我就到此为止。

至于其他需要记住的事情,这只是一个不同的解释器,并且会出现有趣的差异,需要一些适应。

  1. 有些方法的实现方式不同,例如 sleep 10.seconds 会抛出异常(你必须 sleep 10.seconds.to_i),我记得在切换时在 Symbol 类上得到 NoMethodError从 MRI 到 JRuby(不记得哪种方法没有实现),只要记住会有细微的变化
  2. 您将在 gems 中遇到挂起和异常,否则这些情况对您有用(例如 pry)当列出多于一页时)
  3. 一些gem可能会以不同的方式工作,例如,如果您按ctrl+c,则pry(再次)将退出,
  4. 所有内容的加载时间都稍微慢一些, 非常烦人如果没有 zeus,
  5. 你会偶尔得到 java 异常堆栈跟踪,但没有指示发生在哪一行 ruby​​ 代码
  6. Timeout.timeout 当其包裹的网络代码和星形对齐不良时,通常不会按预期工作(这大部分已在 jruby 核心中得到修复,但似乎仍然是在纯 java 中执行自己的网络代码的 gem 的问题)
  7. 第三方代码中线程安全的隐藏问题 如何为高吞吐量多线程 Rails 应用程序选择 gem? - 远离例如,从 EventMachine 来看,
  8. 线程会很棒(由于原生且没有 gil),而纤程则很糟糕(由于 JVM 中没有协程支持,它们是普通线程),这就是为什么在使用赛璐珞时通常无法获得性能提升的原因与 MRI 相比,
  9. 您过去使用 MRI Ruby 作为操作系统中的进程来运行 Rails,您知道如何跟踪它们的 PID、膨胀、运行时间、杀死它们、监视它们等,当您切换到 JRuby 时,这部分并不明显,因为一切已转向单个进程中的线程。 Java 世界有非常好的工具来处理这些问题,但是您必须学习它,
  10. 当您的控制台挂起时,killall -9 ruby​​ 无法解决 jruby 的问题(这种情况更常见)之前),你必须 ps -ef ,然后跟踪正确的进程,而不会杀死你的 netbeans 等(小,但烦人),
  11. 因为我的最后一点,了解 Java 和 JVM 将帮助你摆脱困境在某些情况下(取决于您打算做什么,这可能是您实际上真正需要的),部署服务器的选择将增加或减少这种需求(例如,torquebox 就因此而臭名昭著) ,其他部署选项可能更简单,请参阅 http://thenerdings.blogspot.com/2012/09/pulling-plug-on-torquebox-and-jruby-for.html
  12. ...

另外,看看 jruby 团队对差异的看法,https://github.com/jruby/jruby/wiki/DifferencesBetweenMriAndJruby

但是是的,否则它“与 MRI Ruby 一样”:)

@TobyHede mostly covered issues that you thought of you might have so I'll leave it at that.

As for other things to have in mind, it's simply a different interpreter and funny discrepancies will crop up that will take some adaptation.

  1. some methods are implemented differently, such as sleep 10.seconds will throw exception (you have to sleep 10.seconds.to_i) and I remember getting NoMethodError on Symbol class when switching from MRI to JRuby (don't remember which method wasn't implemented), just have in mind slight variations will be there
  2. you will experience hangs and exceptions in gems that otherwise worked for you (pry for example when listing more then one page)
  3. some gems may work differently, pry (again) will exit if you press ctrl+c for example, pretty annoying
  4. slightly slower load times of everything and no zeus
  5. you'll get occasional java exception stack traces with no indication on which line of ruby code it happened
  6. Timeout.timeout often will not work as expected when its wrapped around net code and stars align badly (this has mostly been fixed in jruby core, but it seems to still be an issue with gems that do their own netcode in pure java)
  7. hidden problems with thread-safety in third party code How do you choose gems for a high throughput multithreaded Rails app? - stay away from EventMachine for example
  8. threads will be awesome (due to nativeness and no gil) and fibers will suck (due to no coroutine support in JVM they're ordinary threads), this is why you often won't get a performance boost with celluloid when compared to MRI
  9. you used to run your rails with MRI Ruby as processes in an OS, you knew how to track their PIDs, bloat, run times, kill them, monitor them etc, this part is not evident when you switch to JRuby because everything has turned to threads in a single process. Java world has very good tools to handle these issues, but its something you'll have to learn
  10. killall -9 ruby doesn't do the trick with jruby when your console hangs (which it does more often then before), you have to ps -ef and then track the proper processes without killing your netbeans etc (minor, but annoying)
  11. due to my last point, knowing Java and the JVM will help you get out of tight spots in certain situations (depending on what you intend to do this may be something you actually really need), choice of deployment server will increase or decrease this need (torquebox for example is a bit notorious for this, other deployment options might be simpler, see http://thenerdings.blogspot.com/2012/09/pulling-plug-on-torquebox-and-jruby-for.html)
  12. ...

Also, see what jruby team says about differences, https://github.com/jruby/jruby/wiki/DifferencesBetweenMriAndJruby

But yeah, otherwise its "just the same as MRI Ruby" :)

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