Slide 1

Slide 1 text

JRuby! Thursday, June 7, 2012

Slide 2

Slide 2 text

Me • Charles Oliver Nutter • @headius • Java developer since 1996 • JRuby developer since 2006 • Starting at Red Hat on Monday! Thursday, June 7, 2012

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

What is JRuby? Thursday, June 7, 2012

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

*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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Try it Out Thursday, June 7, 2012

Slide 10

Slide 10 text

JRuby is the best* Ruby runtime Thursday, June 7, 2012

Slide 11

Slide 11 text

The Team Thursday, June 7, 2012

Slide 12

Slide 12 text

JRuby Team Thursday, June 7, 2012

Slide 13

Slide 13 text

JRuby Team Charlie Thursday, June 7, 2012

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

JRuby Structure JRuby JVM Threads GC Native JIT C API Parser Bytecode JIT Core Classes Java Integ Thursday, June 7, 2012

Slide 17

Slide 17 text

JRuby Structure JRuby Parser Bytecode JIT Core Classes Java Integ JRuby team can focus on implementing JRuby. Thursday, June 7, 2012

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

We could stop working on JRuby and it would continue to get faster. Thursday, June 7, 2012

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Platforms Thursday, June 7, 2012

Slide 22

Slide 22 text

Systems • Best Ruby on Windows? • Exotic platforms: zLinux, OpenVMS, AS/400 • Android’s Dalvik • Embedded JVMs Thursday, June 7, 2012

Slide 23

Slide 23 text

Ruboto Thursday, June 7, 2012

Slide 24

Slide 24 text

Servers • Any Java server can host Ruby • Trinidad • Ruby-style CLI server atop Tomcat • Torquebox • Full Ruby stack atop JBossAS Thursday, June 7, 2012

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Libraries Thursday, June 7, 2012

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Thursday, June 7, 2012

Slide 30

Slide 30 text

Thursday, June 7, 2012

Slide 31

Slide 31 text

Midi Example Thursday, June 7, 2012

Slide 32

Slide 32 text

GC Thursday, June 7, 2012

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

0 3.75 7.5 11.25 15 JRuby Ruby 1.9.3 GC time % Thursday, June 7, 2012

Slide 36

Slide 36 text

Threads Thursday, June 7, 2012

Slide 37

Slide 37 text

Real Parallellism • Ruby thread = JVM thread = native thread • One process can use all cores • One server can handle all requests Thursday, June 7, 2012

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Thursday, June 7, 2012

Slide 41

Slide 41 text

Ruby 1.9 unthreaded Thursday, June 7, 2012

Slide 42

Slide 42 text

Ruby 1.9 unthreaded Ruby 1.9 threaded Thursday, June 7, 2012

Slide 43

Slide 43 text

Ruby 1.9 unthreaded Ruby 1.9 threaded JRuby unthreaded Thursday, June 7, 2012

Slide 44

Slide 44 text

Ruby 1.9 unthreaded Ruby 1.9 threaded JRuby unthreaded JRuby threaded Thursday, June 7, 2012

Slide 45

Slide 45 text

0.2 0.35 0.5 0.65 0.8 one thread two threads three threads four threads threaded_reverse Thursday, June 7, 2012

Slide 46

Slide 46 text

Nonlinear? • More work means more objects • More objects needs memory bandwidth • No different from multi-process Thursday, June 7, 2012

Slide 47

Slide 47 text

Performance Thursday, June 7, 2012

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Thursday, June 7, 2012

Slide 55

Slide 55 text

JRuby/Java 6 JRuby/Java 7 Thursday, June 7, 2012

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

Thursday, June 7, 2012

Slide 60

Slide 60 text

Tools Thursday, June 7, 2012

Slide 61

Slide 61 text

Profiling • Java profilers • VisualVM, YourKit, NetBeans, JXInsight • jruby [--profile | --profile.graph] • jruby -Xreify.classes=true • JVM command-line profilers Thursday, June 7, 2012

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

VisualVM • CPU, memory, thread monitoring • CPU and memory profiling • VisualGC • Heap analysis Thursday, June 7, 2012

Slide 64

Slide 64 text

Thursday, June 7, 2012

Slide 65

Slide 65 text

Thursday, June 7, 2012

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

Thank you! • @headius • jruby.org • torquebox.org Thursday, June 7, 2012