开发 RoR 应用程序后,我需要了解有关 JRuby on Rails 的哪些信息?
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我每天都使用 JRuby。
正确:
有些 gem/插件具有特定于 jruby 的版本,有些根本不起作用。总的来说,我发现的问题很少,并且随着库和平台的成熟,很多问题都消失了(JRuby 已经变得更好了)。
您可以访问 Java,但一般来说您为什么要这样做?
错误:
尽管我猜是这样可以想象一个服务器设置,其中 JVM 的初始启动/预热成本意味着您需要 ping 服务器,JRuby 中没有任何固有的东西可以实现这一点。如果您需要保持服务器处于活动状态,您应该查看您的部署环境。与乘客共享托管时也会发生类似的情况,应用程序在一段时间不活动后可能会出现内存不足的情况。
另外,我们使用 ActiveRecord 也没有任何问题。
I use JRuby everyday.
True:
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:
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.
据我所知,rails 3 与 jruby 100% 兼容,因此该路径上应该没有问题。
与每个新平台一样,您应该通过使用 jruby 让自己适应它。我建议使用 RVM 来做到这一点。
就您的问题而言:
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:
@TobyHede 主要涵盖了您认为可能遇到的问题,所以我就到此为止。
至于其他需要记住的事情,这只是一个不同的解释器,并且会出现有趣的差异,需要一些适应。
sleep 10.seconds
会抛出异常(你必须sleep 10.seconds.to_i
),我记得在切换时在 Symbol 类上得到 NoMethodError从 MRI 到 JRuby(不记得哪种方法没有实现),只要记住会有细微的变化,Timeout.timeout
当其包裹的网络代码和星形对齐不良时,通常不会按预期工作(这大部分已在 jruby 核心中得到修复,但似乎仍然是在纯 java 中执行自己的网络代码的 gem 的问题)killall -9 ruby
无法解决 jruby 的问题(这种情况更常见)之前),你必须 ps -ef ,然后跟踪正确的进程,而不会杀死你的 netbeans 等(小,但烦人),另外,看看 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.
sleep 10.seconds
will throw exception (you have tosleep 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 thereTimeout.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)killall -9 ruby
doesn't do the trick with jruby when your console hangs (which it does more often then before), you have tops -ef
and then track the proper processes without killing your netbeans etc (minor, but annoying)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" :)