18
JRuby http://www.jruby.org Amit Solanki http://vinsol.com [email protected]

Introduction to JRuby

Embed Size (px)

Citation preview

Page 1: Introduction to JRuby

JRubyhttp://www.jruby.org

Amit Solankihttp://[email protected]

Page 2: Introduction to JRuby

Problems with Ruby

• Green threading• No scaling across processors

• Partial Unicode support• Internet connected application needs solid unicode support• No native support for unicode or multibyte string• Rails 1.2 introduced ActiveSupport:Multibyte

• Performance• Interpreted not compiled• Ruby considered “fast enough”• ... but routinely finishes last in benchmark• ... and no work being done in 1.8 to improve

Page 3: Introduction to JRuby

Features missing from Java

• Closures

• Open classes and metaprogramming

• Array, Hash, Regexp literals

• Duck-typing

Page 4: Introduction to JRuby

Introduction to JRuby

• 100% pure java implementation of ruby• current version 1.1 RC 1• based on ruby 1.8.6 (MRI)

• Originally created by Jan Arne Petersen, in 2001• direct port of ruby 1.6 C code

• Developed by JRuby Team• 6 core developers right now• open source developers• full support from Sun Microsystems

Page 5: Introduction to JRuby

Features

• Running on JVM provides• Native threads• Unicode Support• Portability

• Most builtin ruby classes provided• Wide variety of GC options

• Concurrent• Generational• Real-time

• Scalability with native threading(Ruby Thread <=> Java Thread)

• assign work to multiple processors

• better performance at I/O & context-switching operations

Page 6: Introduction to JRuby

Features (contd...)

• Support with interacting with and defining java classes from within ruby• full two way access between the two

• Interpreted, compiled and mixed mode Bean Scripting Framework (BSF) support

• Distributed under tri-license (CPL/GPL/LGPL)

• Support for rubygems, mongrel and (J)Ruby on Rails

• Domain Specific Language (DSL)

Page 7: Introduction to JRuby

JRuby Compiler

• Ahead Of Time (AOT)• compile .rb file to .class file• directly executable, or require/loadable

• Just In Time (JIT)• heavily hit methods compiled at runtime• run existing applications, scripts without modification• optimize methods generated at runtime

• Incremental design• fall back on interpreter for unimplemented bits

Page 8: Introduction to JRuby

Demo

Page 9: Introduction to JRuby

Example

hello_world.rb

Page 10: Introduction to JRuby

Example

testJava.rb

Page 11: Introduction to JRuby

Example

bench_fib_recursive.rb

Page 12: Introduction to JRuby

Comparison:JRuby vs Ruby

jruby bench_fib_recursive.rb

CPU time ¦ System CPU time ¦ Sum of the user and system CPU times ¦ (Elapsed real time)

1.622000 0.000000 1.622000 (1.579000)1.511000 0.000000 1.511000 (1.511000)

ruby bench_fib_recursive.rb

CPU time ¦ System CPU time ¦ Sum of the user and system CPU times ¦ (Elapsed real time)

1.640000 0.010000 1.650000 (1.652467)1.650000 0.000000 1.650000 (1.655654)

Page 13: Introduction to JRuby

Performance & Stability

• JRuby 1.1 - fastest way to run Ruby 1.8 & Rails

• Better garbage collection mechanism

• Dynamic optimization

• Mix-mode virtual machine: compiled JRuby• JRuby Compiler

• Mode:• Interpret• Just-in-time (JIT)• Ahead-of-time (AOT)

Page 14: Introduction to JRuby

Use Cases

• Scripting• JVM too long to start• console clunky when jruby and ruby used together

• Client-side application• app runs long enough• swings getting pretty fast

• Server-side application• server JVM optimizes app at runtime• lots of great servers: Glassfish, JBoss, Oracle, Tomcat, Jetty ...• great monitoring tools• deployment via WAR file

Page 15: Introduction to JRuby

Downsides

• Slow development

• Not enough documentation

• Missing POSIX methods• filesytem support (symlinks, stats, chmod, chown)• process control• JNA library + JRuby = True POSIX

• Database support• ActiveRecord-JDBC still needs more work

• Rmagick support is in progress

• Ruby C extensions, system calls

• Does not support continuations/binding

Page 16: Introduction to JRuby

Core Developers

• Charles Oliver Nutter (Sun Microsystens)http://headius.blogspot.com

• Thomas Enebo (Sun Microsystems)http://www.bloglines.com/blog/ThomasEEnebo/

• Nick Sieger (Sun Microsystems)http://blog.nicksieger.com/

• Ola Bini(Thoughtworks)http://ola-bini.blogspot.com/

• Marcin Mielzynski

• Bill Dortch

Page 17: Introduction to JRuby

Live Implementions

• Media Cast - A media file hosting applicationhttp://mediacast.sun.com/

• Sonar - A free enterprise quality control tool for Java projectshttp://sonar.hortis.ch/

• Mingle - A project collaboration and management tool for Agile software development (Webserver: Jetty & DB Server: Derby)http://studios.thoughtworks.com/mingle-project-intelligence

• SpringBook - Web application to publish your springnote to websitehttp://springbook.playmaru.net/?lang=en

• Openwferu - Open source ruby workflow and BPM enginehttp://openwferu.rubyforge.org/aq.html

• Oracle Mixhttps://mix.oracle.com/

Page 18: Introduction to JRuby

Thank You

(-: