jRuby on Rails 与 Grails
我正在寻求开发一个新的 Web 应用程序,它将重用许多 Java 组件。对我来说,明显的选择是 Grails 或 jRuby on Rails,但我很难找到两者的客观比较。在以下方面是否有任何明确的理由选择其中一个:
- 与现有 Java 组件(持久域之外)集成的便捷性,例如 JMS、EIP
- 对功能测试框架的支持
- 单机上的性能
- 可扩展性
我不认为 寻找与开发人员的可用性或社区活动相关的答案。
(我已经检查过 Grails 与 Rails,它与我无关)
I'm looking to develop a greenfield web application which will reuse a lot of Java components. To me, the obvious options for this are Grails or jRuby on Rails, but I'm having trouble finding objective comparisons of the two. Are there any clear reasons to pick one over the other with respect to:
- ease of integration with existing Java components (outside the persistent domain), e.g. JMS, EIP
- support for functional testing frameworks
- performance on a single machine
- scalability
I am not looking for answers relating to the availability of developers or activity of communities.
(I've checked Grails vs. Rails, and it's not relevant to me)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试两者,然后选择最适合您的语言和环境。确实,开箱即用的 Grails 堆栈更适合 Java 集成,但许多组件只需几行 Ruby 代码即可与 Rails 集成。 Rails 3 是一个很棒的版本,它不需要您使用 ActiveRecord,事实上,为您的模型使用 Hibernate 会很简单。另请参阅 DataMapper、MongoMapper 以及用于 SQL 和 NoSQL 数据库的一整套数据库适配器。
另外,JUnit != 功能测试。相反,请查看 Cucumber + Cucumber-Rails + Capybara + Selenium 以获得集成的浏览器自动化测试体验。查看 https://github.com/elabs/front_end_testing 以获取演示此堆栈的示例应用程序。
我建议 Ruby 更适合作为 Web 集成语言,而 JRuby 恰到好处,可以轻松愉快地与 Java 集成,同时还可以使用大量非 Java 库。不要认为 Groovy 会自动获胜,因为它“更接近”Java。有时,您需要进入一个令人耳目一新的不同环境,以便以新的眼光看待如何解决问题。
披露:作为 JRuby 团队的成员,我的偏见在我的回答中很明显。
Try both, and pick the language and environment that suits you best. It's true that the Grails stack out of the box is more suited towards Java integration, but many components are just a few lines of Ruby code away from integration with Rails. Rails 3 is a great release that doesn't require you to use ActiveRecord, in fact it would be trivial to use Hibernate for your models instead. See also DataMapper, MongoMapper and a whole host of database adapters for SQL and NoSQL databases alike.
Also, JUnit != functional testing. Instead, have a look at Cucumber + Cucumber-Rails + Capybara + Selenium for an integrated browser automation testing experience. Take a look at https://github.com/elabs/front_end_testing for an example application that demonstrates this stack.
I'll suggest that Ruby is better suited as a web integration language, and JRuby hits the sweet spot of making integration with Java easy as well as pleasing while making a wealth of non-Java libraries available to you. Don't think that Groovy automatically wins because it's "closer" to Java. Sometimes you need to step into a refreshingly different environment in order to have a new look at how to solve a problem.
Disclosure: as a member of the JRuby team my bias is evident in my answer.
我非常了解 Grails(现在我正在开发一个 Grails 项目),但不了解 JRuby,所以将此视为可能有偏见的观点:查看 JRuby 文档,看起来 JRuby 与 Java 的集成有点麻烦,因为 Groovy 中的 Java 比 Ruby 中的 Java 更加原生;因此,在 JRuby 中,您有许多特定于 java 的关键字和方法(例如
java_import
、java_send
)。简单地说,Groovy 是一种专门针对 Java 世界的语言,而 JRuby 是 JVM 上的 Ruby。Grails 内置了 JUnit 测试。
关于性能和可扩展性不能说太多,但是考虑到与 Java 的良好集成,当 Groovy 太慢时,人们总是可以用 Java 编写性能关键的部分。
I know Grails very well (right now I'm working on a Grails project), but not JRuby, so take this as a probably biased opinion: looking at the JRuby documentation, it looks that JRubys integration with Java is a bit more cumbersome, since Java is more native in Groovy than it is in Ruby; therefore, in JRuby, you have a lot of java-specific keywords and methods (e.g.
java_import
,java_send
). Put simply, Groovy is a language targeted specifically at the Java world, while JRuby is, well, Ruby put on the JVM.Grails has JUnit tests built in.
Can't say much about performance and scalability, but given the good integration with Java, one can always write performance-critical parts in Java when Groovy is too slow.
使用 groovy 更容易,因为 groovy 基本上是 java。你没有
Ruby 有自己的一堆测试框架,如 rspec/shoulda/cucumber/steak 等等。因为我喜欢 ruby 语法,据我所知,我更喜欢
,grails 在多线程方面更好,因为 Rails 过去并没有过多关注这一点。他们目前正在追赶,所以可能会打平。
均随 jvm 环境而扩展。如果您有 Java 的运行基础架构,则 Grails 更容易集成。
it's easier with groovy, cause groovy is basically java. you do not have big context-switches
ruby has it's own pile of testing frameworks like rspec/shoulda/cucumber/steak and tons more. since i like ruby syntax i would prefer those
as far as i know, grails is better in multithreading, because rails did not fokus too much on that in the past. they are currently catching up, so it might be tie.
both scale with the jvm environement. if you have a running infrastructure for java, grails is easier to integrate.
正如 phoet 所说,Grails 具有一流的 Spring 支持,因此集成 Spring 库通常非常容易 - 这就是许多插件所做的事情,包括 JMS 插件。
Java 代码可以在 JAR 中提供,也可以放入项目的 src/java 目录中。 Groovy 类可以引用可以引用 Groovy 类的 Java 类。它非常无缝。
Grails 支持 HtmlUnit、Selenium-rc 和WebDriver 通过各种插件。 Geb 目前引起了很多兴趣,尤其是与 Spock 结合使用时。< /p>
测试它们。我不知道最近是否有任何比较,但性能通常在很大程度上取决于您的应用程序。 http://grails.org/ 和 http://beta.grails.org/ 都在一台机器上运行 - 并且都是 Grails 应用程序。
我认为通过 Terracotta 集群 Grails 非常容易。如果需要,您也可以使用普通 Tomcat 来完成此操作。有分布式缓存的选项 - SpringSource 以 GemFire 的形式提供了自己的(商业)产品。
希望这对您有所帮助,并且为了充分披露,我是 Grails 团队的一员。
As phoet said, Grails has first-class Spring support, so it's typically very easy to integrate Spring libraries - that's what many plugins do, including the JMS plugin.
Java code can either be provided in JARs or put in to the project's src/java directory. Groovy classes can reference Java classes which can reference Groovy classes. It's pretty seamless.
Grails has support for HtmlUnit, Selenium-rc & WebDriver through various plugins. Geb has a lot of interest at the moment, especially when combined with Spock.
Test them. I don't know if there are any recent comparisons, but performance typically depends heavily on your application. http://grails.org/ and http://beta.grails.org/ are both running on a single machine - and both are Grails applications.
I gather it's pretty easy to cluster Grails via Terracotta. You can also do it with plain Tomcat if you want. There are options for distributed caching - SpringSource has its own (commercial) offering in the form of GemFire.
Hope that helps, and in the interests of full disclosure I'm a member of the Grails team.
最后,您将根据个人选择、对两种语言的舒适程度以及资源的可用性做出决定,但最终,Grails 基于 Spring 的事实让我得出这样的结论:这是正确的选择为我。我知道,如果一切都失败了,我可以重新使用久经考验的真正的 Spring 框架
In the end, you are going to make a decision on personal choice, comfort with the two languages and the availability of resources, but in the end, the fact that Grails is based on Spring led me to the conclusion that it was the right choice for me. I knew that if all else failed I could fall back to utilizing the tried and true Spring Framework
对于 2012 年对这个问题感兴趣的新人...
“使用 @CompileStatic,Groovy 的性能比 Java 慢大约 1-2 倍,没有 Groovy,大约慢 3-5 倍。(...)这意味着对我来说,Groovy 已经为性能必须与 Java 相当的应用程序做好了准备。”
性能测试:Groovy 2.0 与 Java http://java.dzone.com/articles /groovy-20-performance-compared
除了作者之外,我自 2008 年以来一直在使用 Groovy,并取得了巨大成功,不仅用于简历,而且还可以按时完成业务需要的工作。绩效始终与您想做的事情相关。
关于集成,Grails 确实“那么好”。我从来不需要进一步将其与现有库集成。相反,Grails 基于 Spring 的特性使这项工作变得更加容易。
对于那些可能抱怨微基准测试和实际用例的人,这里有一个有点旧的(Grails 1.8)但很好的 Web 框架(Grails 1.3.7): http://www.jtict.com/blog/rails-wicket-grails-play-lift-jsp/
希望这有帮助!
PS.:我想看看 JRuby 和其他真正动态的 JVM 语言的最新基准。
For newcomers interested in this question in 2012...
"With the @CompileStatic, the performance of Groovy is about 1-2 times slower than Java, and without Groovy, it's about 3-5 times slower. (...) This means to me that Groovy is ready for applications where performance has to be somewhat comparable to Java."
Performance Test: Groovy 2.0 vs. Java http://java.dzone.com/articles/groovy-20-performance-compared
And besides the autor, I've used Groovy since 2008 with great success, not only for CV, just to make job done in time business need. Performance is ever relative to what you want to do.
About integration, Grails is really "that good". I've never needed to make one step further to integrate it with existing libraries. On the contrary, the Spring-based nature of Grails made the job even easier.
For those who could complain about micro-benchmarks and real use cases, here is a somewhat old (Grails 1.8) but good one with web frameworks (Grails 1.3.7): http://www.jtict.com/blog/rails-wicket-grails-play-lift-jsp/
Hope this helps!
PS.: I would like to see recent benckmarks with JRuby and other really dynamic JVM languages.