开发者

What do I need to know about JRuby on Rails after developing RoR Apps?

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?


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.


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


@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" :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜