简体   繁体   中英

Use JRuby for Ruby web applications? Is it worth it?

Background: I'm writing a 'standard' (nothing special) web application in Ruby (not Rails) and I need to start thinking about deployment.

So I've been hearing a lot of recommendations to use JRuby to deploy Ruby web applications, regardless of whether you actually need Java libraries or not. How true is this? Is it worth using the Java implementation just for speed? Would I gain anything else by doing so? Would I run into any issues?

PS: I don't know Java that well, so "you can write parts of it in Java" isn't very helpful.

JRuby is one of the most complete ruby implementations (there are a lot other ones out there such as IronRuby, Maglev, Rubinius, XRuby, YARV, MacRuby). It is very comprehensive, therefore, unless you use gems that use native C code, you will very very likely be just fine compatibility-wise.

JRuby is a bit faster than the actual C implementation, but it supports actual threads, whereas the official implementation is struggling a bit into getting it (it still uses Green Threads ). Using Java threads from JRuby is quite trivial, even though it will require you to couple your code with Java (with a little DI , this coupling will only happen once, though).

Another benefit: runtime tools. Java, as a platform , instead of a language, has a lot of runtime tools to help you diagnose problems and check the state of the application (profilers, JConsole, and so on).

Twitter engineers also mentioned that the Ruby VM kinda has trouble being an environment for long lived processes , while the JVM is very good at that, because it's been optimized for that over the last ten years .

Ruby also had a little security issue recently, which did not affect JRuby's implementation.

On the other hand, your project requires more artifacts (JVM, JRuby jars, etc). If you are using an application that will stay alive for long, and you want better runtime support, JRuby can be a great way to go. Otherwise, you can safely wait until you need these things to actually make the move (it is likely to go smoothly).

I use and love JRuby on daily basis, but I suggest you use MRI (aka C-Ruby) unless you have a actual need for JRuby.

Reasons for using JRuby:

  1. Java integration
  2. Restricted environment (your machine has Java installed by not ruby and you don't have root)
  3. Restricted environment (you have ruby installed but don't have root so can't install gems you need)
  4. You reached the limits of Ruby 1.8 performance and cannot use 1.9

From what you've described, you don't have any of the above reasons.

C-Ruby 1.9 has significant performance improvements over C-Ruby 1.8. I've yet to read (or find out for myself) how C-Ruby 1.9 compares with JRuby 1.8 or JRuby 1.9. In anycase, you don't have a performance problem (yet) so don't worry about it.

The good news is, you can start with either and convert later if needs be. It's all Ruby, and the Webrick and Mongrel gems work with both.

As mentioned above, ruby gems that have C extensions cannot be installed under JRuby. Hopefully this will change in the future if ruby C extensions utilize FFI.

http://kenai.com/projects/ruby-ffi/pages/Home

http://isitjruby.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM