Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Euruko 2012 - JRuby

headius
June 07, 2012

Euruko 2012 - JRuby

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.

headius

June 07, 2012
Tweet

More Decks by headius

Other Decks in Technology

Transcript

  1. Me • Charles Oliver Nutter • @headius • Java developer

    since 1996 • JRuby developer since 2006 • Starting at Red Hat on Monday! Thursday, June 7, 2012
  2. Red Hat FAQ • Primary job still JRuby • Expanding

    to help other languages • Working with OpenJDK team • Continuing to support EY JRuby efforts Thursday, June 7, 2012
  3. 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* Thursday, June 7, 2012
  4. *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... Thursday, June 7, 2012
  5. 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 Thursday, June 7, 2012
  6. Getting Started • Need a JVM... • rvm install jruby

    • rvm install jruby-1.7.0-preview1 • Download manually • Unpack, edit PATH, done Thursday, June 7, 2012
  7. JRuby Team Charlie Tom Nick Hiro Marcin Nahi Wayne Subbu

    Douglas Douglas Contribs Douglas Thursday, June 7, 2012
  8. JRuby Team Charlie Tom Nick Hiro Marcin Nahi Wayne Subbu

    Douglas Douglas Contribs Douglas Douglas OpenJDK Douglas Douglas Android Douglas Douglas J9 Douglas Douglas Other JVMs Douglas Thursday, June 7, 2012
  9. JRuby Structure JRuby JVM Threads GC Native JIT C API

    Parser Bytecode JIT Core Classes Java Integ Thursday, June 7, 2012
  10. JRuby Structure JRuby Parser Bytecode JIT Core Classes Java Integ

    JRuby team can focus on implementing JRuby. Thursday, June 7, 2012
  11. JRuby Team Doesn’t Have to Work On* • Memory allocation

    • Garbage collectors • Native threading • Cross-platform • Mobile/Embedded VMs • Native JIT • Tooling • Server environments • Native extensions Thursday, June 7, 2012
  12. We could stop working on JRuby and it would continue

    to get faster. Thursday, June 7, 2012
  13. 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 Thursday, June 7, 2012
  14. Systems • Best Ruby on Windows? • Exotic platforms: zLinux,

    OpenVMS, AS/400 • Android’s Dalvik • Embedded JVMs Thursday, June 7, 2012
  15. Servers • Any Java server can host Ruby • Trinidad

    • Ruby-style CLI server atop Tomcat • Torquebox • Full Ruby stack atop JBossAS Thursday, June 7, 2012
  16. Torquebox • Rack-compatible • Database connectivity • Background daemons •

    Scheduled jobs • Messaging • Asynchronous tasks • Server management • Clustering • In and out-process cache • Web sockets • Authentication • XA Transactions Thursday, June 7, 2012
  17. Torquebox • Rack-compatible • Database connectivity • Background daemons •

    Scheduled jobs • Messaging • Asynchronous tasks • Server management • Clustering • In and out-process cache • Web sockets • Authentication • XA Transactions All Ruby APIs! Thursday, June 7, 2012
  18. Libraries • 340k versioned jars in Maven central • Compare

    to 35k gems in RubyGems.org • Vast majority have no native code • All usable from JRuby Thursday, June 7, 2012
  19. 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! Thursday, June 7, 2012
  20. class Simple attr_accessor :next end top = Simple.new puts 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 } Thursday, June 7, 2012
  21. Real Parallellism • Ruby thread = JVM thread = native

    thread • One process can use all cores • One server can handle all requests Thursday, June 7, 2012
  22. require 'benchmark' ary = (1..1000000).to_a loop { puts Benchmark.measure {

    10.times { ary.each {|i|} } } } Thursday, June 7, 2012
  23. require 'benchmark' ary = (1..1000000).to_a loop { puts Benchmark.measure {

    (1..10).map { Thread.new { ary.each {|i|} } }.map(&:join) } } Thursday, June 7, 2012
  24. 0.2 0.35 0.5 0.65 0.8 one thread two threads three

    threads four threads threaded_reverse Thursday, June 7, 2012
  25. Nonlinear? • More work means more objects • More objects

    needs memory bandwidth • No different from multi-process Thursday, June 7, 2012
  26. Performance • JRuby compiles Ruby to JVM bytecode • JVM

    compiles bytecode to native • Best JIT technology in the world • Getting even better with invokedynamic Thursday, June 7, 2012
  27. def foo bar end def bar baz end def baz

    # ... end foo baz bar Thursday, June 7, 2012
  28. def foo bar end def bar baz end def baz

    # ... end foo bar baz JRuby call logic JRuby call logic Kills many JVM optimizations JRuby on Java 5/6 JRuby call logic Thursday, June 7, 2012
  29. def foo bar end def bar baz end def baz

    # ... end foo bar baz JRuby call logic JRuby call logic Dynamic call logic built into JVM JRuby on Java 7 JRuby call logic X X Thursday, June 7, 2012
  30. def foo bar end def bar baz end def baz

    # ... end foo bar baz Straight through dispatch path JRuby on Java 7 Thursday, June 7, 2012
  31. def foo bar end def bar baz end def baz

    # ... end foo bar baz Optimizations (like inlining) can happen! JRuby on Java 7 Thursday, June 7, 2012
  32. base64 richards neural mandelbrot redblack 0 1.25 2.5 3.75 5

    Times Faster than Ruby 1.9.3 JRuby/Java 6 JRuby/Java 7 Thursday, June 7, 2012
  33. base64 richards neural mandelbrot redblack 0 1.25 2.5 3.75 5

    1.346 1.538 1.914 1.806 1.565 Times Faster than Ruby 1.9.3 JRuby/Java 6 JRuby/Java 7 Thursday, June 7, 2012
  34. base64 richards neural mandelbrot redblack 0 1.25 2.5 3.75 5

    1.346 1.538 1.914 1.806 1.565 2.658 3.44 3.66 4.226 4.32 Times Faster than Ruby 1.9.3 JRuby/Java 6 JRuby/Java 7 Thursday, June 7, 2012
  35. Profiling • Java profilers • VisualVM, YourKit, NetBeans, JXInsight •

    jruby [--profile | --profile.graph] • jruby -Xreify.classes=true • JVM command-line profilers Thursday, June 7, 2012
  36. 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 Thursday, June 7, 2012
  37. VisualVM • CPU, memory, thread monitoring • CPU and memory

    profiling • VisualGC • Heap analysis Thursday, June 7, 2012
  38. 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! Thursday, June 7, 2012