Successfully reported this slideshow.
JRuby!
Me• Charles Oliver Nutter • @headius• Java developer since 1996• JRuby developer since 2006• Starting at Red Hat on Monday!
Red Hat FAQ• Primary job still JRuby• Expanding to help other languages• Working with OpenJDK team• Continuing to support ...
What is JRuby?
Ruby on JVM• Core classes and runtime in Java • Moving parts to Ruby over time• Standard command line• 1.8 and 1.9 compati...
*caveats• Weak low-level UNIX stuff • Improving over time• Poor C extension support • Not maintained...off by default in 1...
JRuby 1.7 (preview)• Ruby 1.9.3 mode by default • Many 1.9 compat fixes• Numerous perf improvements • Java 7 invokedynamic ...
Getting Started• Need a JVM...• rvm install jruby • rvm install jruby-1.7.0-preview1• Download manually • Unpack, edit PAT...
Try it Out
JRuby is the best*  Ruby runtime
The Team
JRuby Team
JRuby Team    Charlie
JRuby Team               Charlie                  TomNick   Hiro   Marcin     Nahi   Wayne   Subbu   Douglas   Douglas    ...
JRuby Team                Charlie                          TomNick   Hiro    Marcin        Nahi     Wayne      Subbu    Do...
JRuby Structure                 JRuby          Bytecode    Core       JavaParser             JIT     Classes    Integ     ...
JRuby Structure                   JRuby             Bytecode    Core      Java    Parser                JIT     Classes   ...
JRuby Team Doesn’t     Have to Work On*•   Memory allocation     •   Native JIT•   Garbage collectors    •   Tooling•   Na...
We could stop workingon JRuby and it wouldcontinue to get faster.
Google Summer        of Code• JRuby accepted as an organization• Eight students! • Shoes, Krypt, evented IO, fibers, Ruboto...
Platforms
Systems• Best Ruby on Windows?• Exotic platforms: zLinux, OpenVMS, AS/400• Android’s Dalvik• Embedded JVMs
Ruboto
Servers• Any Java server can host Ruby• Trinidad • Ruby-style CLI server atop Tomcat• Torquebox • Full Ruby stack atop JBo...
Torquebox•   Rack-compatible         •   Server management•   Database connectivity   •   Clustering•   Background daemons...
Torquebox•   Rack-compatible         •   Server management•   Database connectivity   •   Clustering•   All R    Backgroun...
Libraries
Libraries• 340k versioned jars in Maven central • Compare to 35k gems in RubyGems.org• Vast majority have no native code• ...
Midi Example
GC
JVM GC• Wide array of options • Generation size, worker threads,    concurrency, tenuring...• Many GCs to choose from• Sca...
class Simple  attr_accessor :nextendtop = Simple.newputs Benchmark.measure {  outer = 10  total = 100000  per = 100  outer...
15                GC time %11.25  7.5 3.75   0        JRuby               Ruby 1.9.3
Threads
Real Parallellism• Ruby thread = JVM thread = native thread• One process can use all cores• One server can handle all requ...
require benchmarkary = (1..1000000).to_aloop {  puts Benchmark.measure {    10.times {      ary.each {|i|}    }  }}
require benchmarkary = (1..1000000).to_aloop {  puts Benchmark.measure {    (1..10).map {      Thread.new {        ary.eac...
Ruby 1.9unthreaded
Ruby 1.9    Ruby 1.9unthreaded   threaded
Ruby 1.9    Ruby 1.9unthreaded   threaded  JRubyunthreaded
Ruby 1.9    Ruby 1.9unthreaded   threaded  JRuby        JRubyunthreaded   threaded
threaded_reverse 0.80.65 0.50.35 0.2       one thread   two threads     three threads   four threads
Nonlinear?• More work means more objects• More objects needs memory bandwidth• No different from multi-process
Performance
Performance• JRuby compiles Ruby to JVM bytecode• JVM compiles bytecode to native• Best JIT technology in the world• Getti...
def foo  barenddef bar  baz     foo   bar   bazenddef baz  # ...end
JRuby on Java 5/6def foo  barenddef bar            JRuby            JRuby  baz     foo        call   bar       call     ba...
JRuby on Java 7def foo  bar                   X Xenddef bar             JRuby             JRuby  baz     foo         call ...
JRuby on Java 7def foo  barenddef bar  baz     foo               bar              bazenddef baz  # ...end                S...
JRuby on Java 7def foo  barenddef bar  baz           foo       bar       bazenddef baz  # ...end          Optimizations (l...
JRuby/Java 6   JRuby/Java 7
JRuby/Java 6                   JRuby/Java 7                        Times Faster than Ruby 1.9.3  53.75 2.51.25  0       ba...
JRuby/Java 6                     JRuby/Java 7                            Times Faster than Ruby 1.9.3  53.75 2.5          ...
JRuby/Java 6                     JRuby/Java 7                                 Times Faster than Ruby 1.9.3  5             ...
Tools
Profiling• Java profilers • VisualVM,YourKit, NetBeans, JXInsight• jruby [--profile | --profile.graph]• jruby -Xreify.classes=...
Monitoring• Java Management Extensions (JMX) • Gems available for clients and servers• jconsole and VisualVM• Most servers...
VisualVM• CPU, memory, thread monitoring• CPU and memory profiling• VisualGC• Heap analysis
Your Turn• Try your apps on JRuby and tell us• Turn on JRuby in @travisci• Let us know what you think of JRuby• Help us ma...
Thank you!• @headius• jruby.org• torquebox.org
Euruko 2012 - JRuby
Euruko 2012 - JRuby
Euruko 2012 - JRuby
Euruko 2012 - JRuby
Euruko 2012 - JRuby
Euruko 2012 - JRuby
Euruko 2012 - JRuby
Upcoming SlideShare
Loading in …5
×

Euruko 2012 - JRuby

4,080 views

Published on

JRuby is Ruby for the JVM, right? But what does that really mean? What do you get out of the deal?

We'll explore what makes JRuby unique among Ruby implementations, and why the JVM is a Rubyist's dream come true. Using JRuby means you have the best GC, real threads, easy and scalable deployment, high performance, no-compile cross-platform libraries, and the best monitoring and profiling tools of any VM. And you get it all without leaving Ruby behind. If you're not using JRuby already, this talk will convince you to give it a try.

Published in: Technology
  • Be the first to comment

Euruko 2012 - JRuby

  1. 1. JRuby!
  2. 2. Me• Charles Oliver Nutter • @headius• Java developer since 1996• JRuby developer since 2006• Starting at Red Hat on Monday!
  3. 3. Red Hat FAQ• Primary job still JRuby• Expanding to help other languages• Working with OpenJDK team• Continuing to support EY JRuby efforts
  4. 4. What is JRuby?
  5. 5. Ruby on JVM• Core classes and runtime in Java • Moving parts to Ruby over time• Standard command line• 1.8 and 1.9 compatible • 1.9 default in JRuby 1.7• Drop in replacement for MRI*
  6. 6. *caveats• Weak low-level UNIX stuff • Improving over time• Poor C extension support • Not maintained...off by default in 1.7• Some features differ or unavailable • ObjectSpace, trace funcs, callcc...
  7. 7. JRuby 1.7 (preview)• Ruby 1.9.3 mode by default • Many 1.9 compat fixes• Numerous perf improvements • Java 7 invokedynamic support• Beginning of new optimizing compiler
  8. 8. Getting Started• Need a JVM...• rvm install jruby • rvm install jruby-1.7.0-preview1• Download manually • Unpack, edit PATH, done
  9. 9. Try it Out
  10. 10. JRuby is the best* Ruby runtime
  11. 11. The Team
  12. 12. JRuby Team
  13. 13. JRuby Team Charlie
  14. 14. JRuby Team Charlie TomNick Hiro Marcin Nahi Wayne Subbu Douglas Douglas Douglas Contribs
  15. 15. JRuby Team Charlie TomNick Hiro Marcin Nahi Wayne Subbu Douglas Douglas Douglas Contribs Douglas Douglas Douglas Douglas Douglas Douglas Douglas Other Douglas OpenJDK Android J9 JVMs
  16. 16. JRuby Structure JRuby Bytecode Core JavaParser JIT Classes Integ JVM NativeThreads GC C API JIT
  17. 17. JRuby Structure JRuby Bytecode Core Java Parser JIT Classes IntegJRuby team can focus on implementing JRuby.
  18. 18. JRuby Team Doesn’t Have to Work On*• Memory allocation • Native JIT• Garbage collectors • Tooling• Native threading • Server environments• Cross-platform • Native extensions• Mobile/Embedded VMs
  19. 19. We could stop workingon JRuby and it wouldcontinue to get faster.
  20. 20. Google Summer of Code• JRuby accepted as an organization• Eight students! • Shoes, Krypt, evented IO, fibers, Ruboto, IR dumping, IR to Dalvik, benchmarking• Three more from C42
  21. 21. Platforms
  22. 22. Systems• Best Ruby on Windows?• Exotic platforms: zLinux, OpenVMS, AS/400• Android’s Dalvik• Embedded JVMs
  23. 23. Ruboto
  24. 24. Servers• Any Java server can host Ruby• Trinidad • Ruby-style CLI server atop Tomcat• Torquebox • Full Ruby stack atop JBossAS
  25. 25. Torquebox• Rack-compatible • Server management• Database connectivity • Clustering• Background daemons • In and out-process cache• Scheduled jobs • Web sockets• Messaging • Authentication• Asynchronous tasks • XA Transactions
  26. 26. Torquebox• Rack-compatible • Server management• Database connectivity • Clustering• All R Background daemons • In and out-process cache• Scheduled jobs uby • Web sockets• Messaging APIs • Authentication• Asynchronous tasks • ! XA Transactions
  27. 27. Libraries
  28. 28. Libraries• 340k versioned jars in Maven central • Compare to 35k gems in RubyGems.org• Vast majority have no native code• All usable from JRuby
  29. 29. Midi Example
  30. 30. GC
  31. 31. JVM GC• Wide array of options • Generation size, worker threads, concurrency, tenuring...• Many GCs to choose from• Scales up to massive heaps• Best GCs in the world!
  32. 32. class Simple  attr_accessor :nextendtop = Simple.newputs Benchmark.measure {  outer = 10  total = 100000  per = 100  outer.times do    total.times do      per.times { Simple.new }      s = Simple.new      top.next = s      top = s    end  end}
  33. 33. 15 GC time %11.25 7.5 3.75 0 JRuby Ruby 1.9.3
  34. 34. Threads
  35. 35. Real Parallellism• Ruby thread = JVM thread = native thread• One process can use all cores• One server can handle all requests
  36. 36. require benchmarkary = (1..1000000).to_aloop {  puts Benchmark.measure {    10.times {      ary.each {|i|}    }  }}
  37. 37. require benchmarkary = (1..1000000).to_aloop {  puts Benchmark.measure {    (1..10).map {      Thread.new {        ary.each {|i|}      }    }.map(&:join)  }}
  38. 38. Ruby 1.9unthreaded
  39. 39. Ruby 1.9 Ruby 1.9unthreaded threaded
  40. 40. Ruby 1.9 Ruby 1.9unthreaded threaded JRubyunthreaded
  41. 41. Ruby 1.9 Ruby 1.9unthreaded threaded JRuby JRubyunthreaded threaded
  42. 42. threaded_reverse 0.80.65 0.50.35 0.2 one thread two threads three threads four threads
  43. 43. Nonlinear?• More work means more objects• More objects needs memory bandwidth• No different from multi-process
  44. 44. Performance
  45. 45. Performance• JRuby compiles Ruby to JVM bytecode• JVM compiles bytecode to native• Best JIT technology in the world• Getting even better with invokedynamic
  46. 46. def foo barenddef bar baz foo bar bazenddef baz # ...end
  47. 47. JRuby on Java 5/6def foo barenddef bar JRuby JRuby baz foo call bar call bazend logic logicdef baz # ...end Kills many JVM optimizations
  48. 48. JRuby on Java 7def foo bar X Xenddef bar JRuby JRuby baz foo call bar call bazend logic logicdef baz # ...end Dynamic call logic built into JVM
  49. 49. JRuby on Java 7def foo barenddef bar baz foo bar bazenddef baz # ...end Straight through dispatch path
  50. 50. JRuby on Java 7def foo barenddef bar baz foo bar bazenddef baz # ...end Optimizations (like inlining) can happen!
  51. 51. JRuby/Java 6 JRuby/Java 7
  52. 52. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.51.25 0 base64 richards neural mandelbrot redblack
  53. 53. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.5 1.914 1.806 1.538 1.5651.25 1.346 0 base64 richards neural mandelbrot redblack
  54. 54. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 4.226 4.323.75 3.66 3.44 2.5 2.658 1.914 1.806 1.538 1.5651.25 1.346 0 base64 richards neural mandelbrot redblack
  55. 55. Tools
  56. 56. Profiling• Java profilers • VisualVM,YourKit, NetBeans, JXInsight• jruby [--profile | --profile.graph]• jruby -Xreify.classes=true• JVM command-line profilers
  57. 57. Monitoring• Java Management Extensions (JMX) • Gems available for clients and servers• jconsole and VisualVM• Most servers provide additional tools• New Relic, etc have JVM support
  58. 58. VisualVM• CPU, memory, thread monitoring• CPU and memory profiling• VisualGC• Heap analysis
  59. 59. Your Turn• Try your apps on JRuby and tell us• Turn on JRuby in @travisci• Let us know what you think of JRuby• Help us make JRuby even better!
  60. 60. Thank you!• @headius• jruby.org• torquebox.org

×