SlideShare a Scribd company logo
Why JRuby?
Who?




  Thomas      Charlie
@tom_enebo   @headius
What is JRuby?
JRuby is Ruby! *
   1.8.7 & 1.9.3 compatibility
   drop-in replacement

                         * see next slide
*caveats

• Weak but improving low-level UNIX stuff
• No C extension support
 • Not maintained...off by default in 1.7
• Some features differ or unavailable
 • ObjectSpace, trace funcs, callcc, fork...
JRuby is Ruby
     ...and then some?
Announcing JRuby 1.7.0

• Ruby 1.9.3 compat (--1.8 for 1.8.7)
• Java 7 invokedynamic support
• Much awesomeness over 1.6.x
Getting Started

1. Install a JVM
2. rvm install jruby
3. Profit!
        % jruby -e ‘puts “wowee”’
The JRuby Difference
JRuby Team

                  Charlie                       Tom




Nick   Hiro   Marcin        Nahi    Wayne      Subbu   Douglas   Douglas
                                                                  Douglas
                                                                  Contribs




                Douglas
                 Douglas       Douglas
                                Douglas     Douglas
                                              Other
                                             Douglas
                 OpenJDK         Android
                                               JVMs
JRuby

                JRuby
Yoko




          JVM
J. Rose



           OS (libc, ...)
MRI

nobu
           MRI




       OS (libc, ...)
JRuby

                JRuby
Yoko




          JVM
J. Rose



           OS (libc, ...)
We get it for Free!

               JVM
J. Rose



  Garbage                     Profiled
               Native JIT   Optimizations
 Collection

  Native        Tooling     Cross Platform
 Threading
Profile: John Rose
    • JVM Engineer since 1997
    • Invented C* Language
    • JSR 292 lead
JVM over time
(what if we were lazy?)
Go Java Go!                       300% for free
             JRuby 1.0.3 (bm_red_black_tree.rb)

 30



22.5



 15



 7.5



   0
  Java 1.4     Java 5                 Java 6             Java 7
Go Java Go!                          300% for free
             JRuby 1.0.3 (bm_red_black_tree.rb)                MRI 1.8

 30



22.5



 15



 7.5



   0
  Java 1.4               Java 5                   Java 6                 Java 7
JVM Benefits
Cross-Platform
JVM is everywhere

• Unix++, Windows
• Exotic platforms: zLinux, OpenVMS, AS/400
• Mobile: Android’s Dalvik, Embedded JVMs
Why JRuby? - RubyConf 2012
Java bytecode ==
    portability
actionmailer-javamail, active_documentum, activerecord-jdbc-adapter, activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2-
adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord-
    jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars,
    akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core,
   bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin,
 bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra-
   jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter,
  do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop,
    dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston-
   rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back,
 gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass,
 hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector,
 iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker,
            ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify,
java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state-
                machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger,
  javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3,
      jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby-
      httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button,
  jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback,
       logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah,
mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin,
      neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r,
nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2-
               kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core,
      qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge-
    jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah,
        redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack-
commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty,
     rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome,
  rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core-
 api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon-
     zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon-
 deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox-
    cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming,
 torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe-
 javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet-
                                                                   streamer, wrest, wrong, xdojava, xqruby, zookeeper
actionmailer-javamail, active_documentum, activerecord-jdbc-adapter, activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2-
adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord-
    jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars,
    akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core,
   bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin,
 bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra-
   jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter,
  do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop,
    dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston-
   rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back,
 gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass,
 hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector,
 iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker,
            ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify,
java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state-
                machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger,
  javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3,



                                                No build tools!
      jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby-
      httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button,
  jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback,
       logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah,
mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin,
      neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r,
nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2-
               kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core,
      qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge-
    jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah,
        redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack-
commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty,
     rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome,
  rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core-
 api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon-
     zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon-
 deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox-
    cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming,
 torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe-
 javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet-
                                                                   streamer, wrest, wrong, xdojava, xqruby, zookeeper
Libraries
 Lucene     Neo4j
                         Selenium

47k libraries in Maven
Hadoop         EHCache

    JMonkeyEngine
                           Sitemesh
Languages/Polyglot
      Clojure                 Scala

                     Jython


Rhino/Nashorn/                Groovy
DynJS (JavaScript)
             Micro Focus JVM Visual COBOL
Polyglot

• Use right tool for the right job
• Running in the same VM
• Another dimension of libraries
GC
GC Matters

• Applications grow over time
• Ruby is very object-heavy
• Multiprocess multiplies the problem
• You will eventually have issues
JVM GC

• Wide array of options
• Many GCs to choose from
• Scales up to massive heaps
• Best GCs in the world!
OpenJDK GCs

• Parallel: multi-core stop-the-world
• Concurrent: STW young, concurrent old
• G1: concurrent young and old
• Serial: single-thread STW
Object Homogeneity

• Everything expressed as JVM objects
• Everything shares the same infrastructure
 • Including extensions, libraries, etc
• One GC to rule them all
 • And one standard memory model
gc_demo.rb


• Heavy GC, mix of old and young
• Steadily growing heap use
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
}
Ruby 1.9.3              JRuby
8000



6000



4000



2000



   0
                    GC count
Ruby 1.9.3              JRuby
10000



 1000



  100



   10



    1
                     GC count
15
        Ruby 1.9.3               JRuby



11.25




  7.5




 3.75




   0
                     GC time %
Ruby 2.0.0                      JRuby
                               Time per GC versus heap usage
              300ms



              225ms
Time per GC




              150ms



              75ms



               0ms
               188KB/29MB                  27MB/127MB               199MB/238MB
                                   Heap usage (MRI/JRuby)
Ruby 2.0.0                      JRuby
                                   Time per GC versus heap usage

                   :-(

                   :-(
User Unhappiness




                   :-/

                   :-|

                   :-)
                   188KB/29MB                  27MB/127MB               199MB/238MB
                                       Heap usage (MRI/JRuby)
Ruby 2.0.0

                   4,000




                   3,000
Time Per GC (ms)




                   2,000




                   1,000




                      0
                           0M   1,250M       2,500M     3,750M   5,000M
                                            Heap Size
Findings

• Lower, more uniform GC times
• Reduced or eliminated pauses
• Very large heaps are no problem
• Predictable, consistent experience
Threads
Real Parallellism

• Ruby thread = JVM thread = native thread
• One process can use all cores
• One server can handle all requests
require 'benchmark'

ary = (1..1000000).to_a

loop {
  puts Benchmark.measure {
    10.times {
      ary.each {|i|}
    }
  }
}
require 'benchmark'

ary = (1..1000000).to_a

loop {
  puts Benchmark.measure {
    (1..10).map {
      Thread.new {
        ary.each {|i|}
      }
    }.map(&:join)
  }
}
Why JRuby? - RubyConf 2012
Ruby 1.9
unthreaded
Ruby 1.9    Ruby 1.9
unthreaded   threaded
Ruby 1.9    Ruby 1.9
unthreaded   threaded




  JRuby
unthreaded
Ruby 1.9    Ruby 1.9
unthreaded   threaded




  JRuby        JRuby
unthreaded   threaded
threaded_reverse
                     Per-iteration time versus thread count
 0.8s



0.65s



 0.5s



0.35s



 0.2s
        one thread      two threads        three threads      four threads
Nonlinear?

• More work means more objects
• Allocation/GC needs memory bandwidth
• No different from multi-process
Why JRuby? - RubyConf 2012
Tools
Profiling

• Java profilers
 • VisualVM,YourKit, NetBeans, JXInsight
• jruby [--profile | --profile.graph]
• jruby -Xreify.classes=true
• JVM command-line profilers
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
VisualVM

• CPU, memory, thread monitoring
• CPU and memory profiling
• VisualGC
• Heap analysis
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
JRuby Goodies
Scripting Java
JavaFX straight port



      Simple Clock
@minute_hand = Path.new.tap do |mh|       Draw minute hand
  mh.setFill(Color::BLACK)
  mh.getElements.add MoveTo.new(4, -4)
  mh.getElements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.getElements.add LineTo.new(0, -radius)
  mh.getTransforms.add Rotate.new
end
                                        Implement Java Event
class Refresher
  include EventHandler                        handler
  def handle(event); event.source.refresh; end
end
                                       refresh timeline every 1s
Timeline.new.tap do |time|
  time.setCycleCount Timeline::INDEFINITE
  time.getKeyFrames.add(Keyframe.new(Duration.millis(1000)),
                        Refresher.new)
  time.play
end
getFooBar -> fooBar
@minute_hand = Path.new.tap do |mh|
  mh.setFill(Color::BLACK)          was getElements
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end                            was getTransforms
class Refresher
  include EventHandler
  def handle(event); event.source.refresh; end
end

Timeline.new.tap do |time|
  time.setCycleCount Timeline::INDEFINITE
  time.keyFrames.add(Keyframe.new(Duration.millis(1000)),
                     Refresher.new)
  time.play
end                  was getKeyFrames
setFoo(a) -> foo = a
@minute_hand = Path.new.tap do |mh|
  mh.fill = Color::BLACK            was setFill
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end

class Refresher
  include EventHandler
  def handle(event); event.source.refresh; end
end

Timeline.new.tap do |time|
                                was setCycleCount
  time.cycleCount = Timeline::INDEFINITE
  time.keyFrames.add(Keyframe.new(Duration.millis(1000)),
                     Refresher.new)
  time.play
end
camelCase -> camel_case
@minute_hand = Path.new.tap do |mh|
  mh.fill = Color::BLACK
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end

class Refresher
  include EventHandler
  def handle(event); event.source.refresh; end
end

Timeline.new.tap do |time|             was cycleCount
  time.cycle_count = Timeline::INDEFINITE
  time.key_frames.add(Keyframe.new(Duration.millis(1000)),
                      Refresher.new)
  time.play
end                                  was keyFrames
Procs as interfaces
@minute_hand = Path.new.tap do |mh|
  mh.fill = Color::BLACK
  mh.elements.add MoveTo.new(4, -4)
  mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false)
  mh.elements.add LineTo.new(0, -radius)
  mh.transforms.add Rotate.new
end                                   No more extra class
Timeline.new.tap do |time|
  time.cycle_count = Timeline::INDEFINITE
  time.key_frames.add Keyframe.new(Duration.millis(1000)) {refresh}
  time.play
end
Common Adornments
                     ‘add’ becomes ‘<<‘
@minute_hand = Path.new.tap do   |mh|
  mh.fill = Color::BLACK
  mh.elements << MoveTo.new(4,   -4)
  mh.elements << ArcTo.new(-1,   -1, 0, -4, -4, false, false)
  mh.elements << LineTo.new(0,   -radius)
  mh.transforms << Rotate.new
end

Timeline.new.tap do |time|
  time.cycle_count = Timeline::INDEFINITE
  time.key_frames << Keyframe.new(Duration.millis(1000)) {refresh}
  time.play
end
Purugin

• Minecraft scripting in JRuby
• Clean and simple DSL
• Purogo: LOGO for Minecraft
turtle("four-sided triangle") do |*args|
  dim = (args[0] || 5).to_i
  block_type = (args[1] || :stone).to_sym

  layer do
    4.times do |i|
      forward dim
      turnleft 90
    end
  end
  
  pivot do
    block :none
    forward 1
    turnleft 90
    forward 1
    turnup 90
    forward 1
    turndown 90
    turnright 90
    block block_type
  end

  block block_type
  (1...dim).step(2).to_a.reverse.each do |i|
    dim = i
    layer
    pivot
  end
end
Why JRuby? - RubyConf 2012
Pimping a side-project


https://github.com/enebo/Purugin
Java Native Extensions
Native Extensions Suck
“Look, nobody enjoys
shooting penguins, but if
you have to shoot penguins,
well, you might as well
enjoy it.”
           - Free Waterfall Sr.
Flowchart of Shame
Can I write it in Ruby?               Script Java?
                               no
            yes                             no

    Does it need                     Can I use FFI?
    to be n times
       faster?                              no
                          no
                                    Native Extension
Java Native Extensions

• Written in Java
 • Have same performance as Java
 • Use same GC as JRuby
 • First Class Citizens
Performance
Go Java Go!                       300% for free
             JRuby 1.0.3 (bm_red_black_tree.rb)

 30



22.5



 15



 7.5



   0
  Java 1.4     Java 5                 Java 6             Java 7
Go JRuby Go!
                 OpenJDK 8 (bm_red_black_tree.rb)

8



6



4



2



0
 1.0.3   1.1.6          1.4.0       1.5.6           1.6.8   1.7.0
Severe gains???
                   OpenJDK 8 (bm_red_black_tree.rb)

  9
            Severe perf bottleneck(s)
6.75



 4.5



2.25



  0
   1.0.3   1.1.6          1.4.0       1.5.6           1.6.8   1.7.0
1.0.3 & red_black_tree
       -J-verbose:gc
          [GC (Allocation Failure) 223608K->96408K(330752K), 0.0159780 secs]
         [GC (Allocation Failure) 208920K->100792K(335168K), 0.0157550 secs]
         [GC (Allocation Failure) 213304K->105144K(332160K), 0.0181010 secs]
8.1s     [GC (Allocation Failure) 205112K->108920K(334400K), 0.0187580 secs]
         [GC (Allocation Failure) 208888K->112712K(329152K), 0.0154440 secs]
                                       +28 more


         [GC (Allocation Failure) 313780K->199892K(339072K), 0.0142010 secs]
         [GC (Allocation Failure) 318420K->204420K(331520K), 0.0175690 secs]
8.4s     [GC (Allocation Failure) 306948K->208316K(335680K), 0.0188120 secs]
           [Full GC (Ergonomics) 208316K->54991K(352256K), 0.2709750 secs]
          [GC (Allocation Failure) 157519K->58959K(349248K), 0.0120840 secs]
                                       +28 more



                              Moar Objects!
1.7.0 & red_black_tree
-J-verbose:gc
  [GC (Allocation Failure) 155729K->39697K(207296K), 0.0072730 secs]
                             0.963s
  [GC (Allocation Failure) 160785K->40657K(208320K), 0.0108620 secs]
                             0.968s
  [GC (Allocation Failure) 161745K->41649K(210112K), 0.0083760 secs]
                             0.968s
  [GC (Allocation Failure) 166193K->39729K(210688K), 0.0070670 secs]
                              0.99s
OpenJDK 8 (bm_red_black_tree.rb)

  3



2.25



 1.5



0.75



  0
   1.1.6   1.4.0          1.5.6          1.6.8   1.7.0
OpenJDK 8 (bm_red_black_tree.rb)

  3

                                      JVM Feature!
2.25



 1.5



0.75



  0
   1.1.6   1.4.0          1.5.6          1.6.8       1.7.0
Performance

• JRuby compiles Ruby to JVM bytecode
• JVM compiles bytecode to native
• Best JIT technology in the world
• Getting even better with invokedynamic
How to Optimize Ruby
• Do less work
 • Reduce dispatch and call overhead
 • Reduce memory overhead
• Find static patterns
 • Profile running code
 • Emit optimized version with guards
JVM Optimizations
• Profiling
 • Watch code, optimize hottest paths
• Inlining
 • Combine code, optimize as a whole
• Escape analysis
 • Eliminate transient objects
def foo; Object.new; end
def invoker; foo; end
i = 0
while i < 10000
  invoker
  i+=1
end
Inline foo into invoker
  def invoker; Object.new; end
  i = 0
  while i < 10000
    invoker
    i+=1
  end
Inline invoker into loop

  i = 0
  while i < 10000
    Object.new
    i+=1
  end
Object is transient

i = 0
while i < 10000

  i+=1
end
Loop does nothing

i = 10000
Variable i is never read
InvokeDynamic

• Java 7+ feature
• Allows us to teach JVM about Ruby
 • Dynamic calls can inline
 • Constants become truly constant
 • JVM’s best optimizations can work
Does It Work?
def foo; 1; end
def invoker; foo; end
N.times do
  i = 0
  while i < 10000
   invoker
   i+=1
  end
end
$ jruby -J-XX:+UnlockDiagnosticVMOptions 
         -J-XX:+PrintInlining 
         -J-XX:+PrintCompilation 
         script.rb
      79    1    b        java.lang.String::hashCode (55 bytes)
     109    2    b        java.util.Properties$LineReader::readLine (452 bytes)
                   @ 48  java.io.Reader::read (9 bytes)   never executed
                   @ 62  java.io.FilterInputStream::read (9 bytes)
                   @ 303  java.lang.System::arraycopy (0 bytes)    (intrinsic)
                   @ 388  java.io.Reader::read (9 bytes)   never executed
....
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
def foo; 1; end
                   def invoker; foo; end
                   N.times do
                     i = 0
                     while i < 10000
                      invoker
                      i+=1
                     end
                   end


3321 190     b        ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes)
  @ 6   org.jruby.RubyFixnum::op_lt (22 bytes)   inline (hot)
  @ 66   org.jruby.RubyBasicObject::isTrue (15 bytes)    inline (hot)
  @ 6   ruby.__dash_e__::method__1$RUBY$invoker (9 bytes)    inline (hot)
    @ 6   ruby.__dash_e__::method__0$RUBY$foo (7 bytes)    inline (hot)
  @ 5   org.jruby.RubyFixnum::op_plus_one (31 bytes)    inline (hot)
Does It Help?
Why JRuby? - RubyConf 2012
JRuby/Java 6   JRuby/Java 7
JRuby/Java 6                   JRuby/Java 7
                        Times Faster than Ruby 1.9.3
  5



3.75



 2.5



1.25



  0
       base64      richards        neural      mandelbrot     redblack
JRuby/Java 6                     JRuby/Java 7
                            Times Faster than Ruby 1.9.3
  5



3.75



 2.5

                                    1.914          1.806
                    1.538                                         1.565
1.25   1.346




  0
         base64      richards          neural      mandelbrot      redblack
JRuby/Java 6                     JRuby/Java 7
                                 Times Faster than Ruby 1.9.3
  5


                                                                4.226           4.32
3.75
                                                 3.66
                                 3.44


 2.5           2.658


                                         1.914          1.806
                         1.538                                          1.565
1.25   1.346




  0
         base64           richards          neural      mandelbrot       redblack
smooth_sort
# Original Author: Keith Schwarz (htiek@cs.stanford.edu)
#
# Translated to Ruby by Chuck Remes (chuckremes on github)
#
# An implementation of Dijkstra's Smoothsort algorithm, a modification of
# heapsort that runs in O(n lg n) in the worst case, but O(n) if the data
# are already sorted. For more information about how this algorithm works
# and some of the details necessary for its proper operation, please see
#
#          http://www.keithschwarz.com/smoothsort/
Ruby 1.8.7   Ruby 1.9.3          Ruby 2.0.0   JRuby

100000



 75000



 50000



 25000

                                         19590.7
                        11439
              4750
     0
                         Iterations per second
And Rails?
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
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!
• JRuby BOF in Room C at 6:30PM
JRUBY BOOK
Why JRuby? - RubyConf 2012
Thank you!

• @headius
• jruby.org
• torquebox.org

More Related Content

KEY
Aloha RubyConf 2012 - JRuby
Charles Nutter
 
KEY
Практики применения JRuby
.toster
 
PDF
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
Yusuke Yamamoto
 
KEY
State of the art server side java script
Thibaud Arguillere
 
KEY
State of the art: server-side javaScript - NantesJS
Alexandre Morgaut
 
PDF
Java 7 Preview
Alex Miller
 
PPT
Object Oriented Programming-JAVA
Home
 
PDF
State of the art: Server-Side JavaScript - dejeuner fulljs
Alexandre Morgaut
 
Aloha RubyConf 2012 - JRuby
Charles Nutter
 
Практики применения JRuby
.toster
 
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
Yusuke Yamamoto
 
State of the art server side java script
Thibaud Arguillere
 
State of the art: server-side javaScript - NantesJS
Alexandre Morgaut
 
Java 7 Preview
Alex Miller
 
Object Oriented Programming-JAVA
Home
 
State of the art: Server-Side JavaScript - dejeuner fulljs
Alexandre Morgaut
 

What's hot (20)

PPTX
ClassLoader Leaks
Mattias Jiderhamn
 
PDF
Demistifying OSGi - Colombo Java Meetup 2013
Sameera Jayasoma
 
PDF
JRuby Jam Session
Engine Yard
 
PPTX
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
KEY
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
PDF
JVM for Dummies - OSCON 2011
Charles Nutter
 
PPTX
HotSpotコトハジメ
Yasumasa Suenaga
 
PDF
Java Tools and Techniques for Solving Tricky Problem
Will Iverson
 
KEY
State of the art - server side JavaScript - web-5 2012
Alexandre Morgaut
 
PPTX
Smartcard Vulnerabilities In Modern Banking Malwaremalware
Positive Hack Days
 
PPT
Jvm performance tuning
Igor Igoroshka
 
PDF
Project Build With Maven
elliando dias
 
PDF
JAVA AND ANDROID OS_PRESENTATION
Benjamin Agboola
 
PDF
Torquebox - O melhor dos dois mundos
Bruno Oliveira
 
PDF
groovy and concurrency
Paul King
 
PPT
Jdk Tools For Performance Diagnostics
Dror Bereznitsky
 
PDF
Java Runtime: повседневные обязанности JVM
odnoklassniki.ru
 
PDF
Jvm internals
Luiz Fernando Teston
 
PDF
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
tamtam180
 
PDF
JCR In 10 Minutes
Bertrand Delacretaz
 
ClassLoader Leaks
Mattias Jiderhamn
 
Demistifying OSGi - Colombo Java Meetup 2013
Sameera Jayasoma
 
JRuby Jam Session
Engine Yard
 
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
JVM for Dummies - OSCON 2011
Charles Nutter
 
HotSpotコトハジメ
Yasumasa Suenaga
 
Java Tools and Techniques for Solving Tricky Problem
Will Iverson
 
State of the art - server side JavaScript - web-5 2012
Alexandre Morgaut
 
Smartcard Vulnerabilities In Modern Banking Malwaremalware
Positive Hack Days
 
Jvm performance tuning
Igor Igoroshka
 
Project Build With Maven
elliando dias
 
JAVA AND ANDROID OS_PRESENTATION
Benjamin Agboola
 
Torquebox - O melhor dos dois mundos
Bruno Oliveira
 
groovy and concurrency
Paul King
 
Jdk Tools For Performance Diagnostics
Dror Bereznitsky
 
Java Runtime: повседневные обязанности JVM
odnoklassniki.ru
 
Jvm internals
Luiz Fernando Teston
 
Introduction httpClient on Java11 / Java11時代のHTTPアクセス再入門
tamtam180
 
JCR In 10 Minutes
Bertrand Delacretaz
 
Ad

Viewers also liked (9)

PDF
Abstraction of JRuby Kaigi2010
Koichiro Ohba
 
PDF
Megyünk a Balcsira?
Chrisjazzingup
 
PDF
Introduction to JRuby
Amit Solanki
 
PDF
J Ruby Kungfu Rails
Daniel Lv
 
KEY
Introduction to JRuby
ajuckel
 
PDF
Intro to J Ruby
Frederic Jean
 
KEY
jRuby: The best of both worlds
Christopher Spring
 
PDF
Focuslight, Jobs and OSS - HackGirls bar vol.2
Koichiro Ohba
 
Abstraction of JRuby Kaigi2010
Koichiro Ohba
 
Megyünk a Balcsira?
Chrisjazzingup
 
Introduction to JRuby
Amit Solanki
 
J Ruby Kungfu Rails
Daniel Lv
 
Introduction to JRuby
ajuckel
 
Intro to J Ruby
Frederic Jean
 
jRuby: The best of both worlds
Christopher Spring
 
Focuslight, Jobs and OSS - HackGirls bar vol.2
Koichiro Ohba
 
Ad

Similar to Why JRuby? - RubyConf 2012 (20)

KEY
Euruko 2012 - JRuby
Charles Nutter
 
PDF
Glass fish rubyconf-india-2010-Arun gupta
ThoughtWorks
 
PDF
GlassFish can support multiple Ruby frameworks ... really ?
Arun Gupta
 
KEY
Jruby synergy-of-ruby-and-java
Keith Bennett
 
KEY
JRuby: What's Different (RORO Melbourne October 2011)
Charles Nutter
 
PDF
JRuby @ Boulder Ruby
Nick Sieger
 
PDF
Core java 5 days workshop stuff
Rajiv Gupta
 
PDF
Monkeybars in the Manor
martinbtt
 
PDF
Dynamic Languages & Web Frameworks in GlassFish
IndicThreads
 
PDF
JRuby talk / 26.03.2014 / @vbalazs
Balázs Varga
 
PDF
Bitter Java, Sweeten with JRuby
Brian Sam-Bodden
 
PPTX
Introduction to java
Sandeep Rawat
 
PDF
JRoR Deploying Rails on JRuby
elliando dias
 
PDF
Understanding the Dalvik Virtual Machine
National Cheng Kung University
 
ODP
First Day With J Ruby
Praveen Kumar Sinha
 
PDF
JRuby Basics
elliando dias
 
PDF
JRuby - The Perfect Alternative
Ram Vijapurapu
 
PPT
Practical JRuby
David Keener
 
PDF
JRuby - Programmer's Best Friend on JVM
Raimonds Simanovskis
 
PDF
Behind the Scenes at LiveJournal: Scaling Storytime
SergeyChernyshev
 
Euruko 2012 - JRuby
Charles Nutter
 
Glass fish rubyconf-india-2010-Arun gupta
ThoughtWorks
 
GlassFish can support multiple Ruby frameworks ... really ?
Arun Gupta
 
Jruby synergy-of-ruby-and-java
Keith Bennett
 
JRuby: What's Different (RORO Melbourne October 2011)
Charles Nutter
 
JRuby @ Boulder Ruby
Nick Sieger
 
Core java 5 days workshop stuff
Rajiv Gupta
 
Monkeybars in the Manor
martinbtt
 
Dynamic Languages & Web Frameworks in GlassFish
IndicThreads
 
JRuby talk / 26.03.2014 / @vbalazs
Balázs Varga
 
Bitter Java, Sweeten with JRuby
Brian Sam-Bodden
 
Introduction to java
Sandeep Rawat
 
JRoR Deploying Rails on JRuby
elliando dias
 
Understanding the Dalvik Virtual Machine
National Cheng Kung University
 
First Day With J Ruby
Praveen Kumar Sinha
 
JRuby Basics
elliando dias
 
JRuby - The Perfect Alternative
Ram Vijapurapu
 
Practical JRuby
David Keener
 
JRuby - Programmer's Best Friend on JVM
Raimonds Simanovskis
 
Behind the Scenes at LiveJournal: Scaling Storytime
SergeyChernyshev
 

More from Charles Nutter (20)

PDF
The Year of JRuby - RubyC 2018
Charles Nutter
 
PDF
Down the Rabbit Hole: An Adventure in JVM Wonderland
Charles Nutter
 
PDF
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 
PDF
JRuby 9000 - Optimizing Above the JVM
Charles Nutter
 
PDF
JRuby and Invokedynamic - Japan JUG 2015
Charles Nutter
 
PDF
JRuby 9000 - Taipei Ruby User's Group 2015
Charles Nutter
 
PDF
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
PDF
Open Source Software Needs You!
Charles Nutter
 
PDF
InvokeBinder: Fluent Programming for Method Handles
Charles Nutter
 
PDF
Over 9000: JRuby in 2015
Charles Nutter
 
PDF
Doing Open Source the Right Way
Charles Nutter
 
PDF
JRuby: The Hard Parts
Charles Nutter
 
PDF
Bringing Concurrency to Ruby - RubyConf India 2014
Charles Nutter
 
PDF
Beyond JVM - YOW! Sydney 2013
Charles Nutter
 
PDF
Beyond JVM - YOW! Brisbane 2013
Charles Nutter
 
PDF
Beyond JVM - YOW Melbourne 2013
Charles Nutter
 
PDF
Down the Rabbit Hole
Charles Nutter
 
PDF
The Future of JRuby - Baruco 2013
Charles Nutter
 
PDF
High Performance Ruby - E4E Conference 2013
Charles Nutter
 
PDF
Invokedynamic in 45 Minutes
Charles Nutter
 
The Year of JRuby - RubyC 2018
Charles Nutter
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Charles Nutter
 
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 
JRuby 9000 - Optimizing Above the JVM
Charles Nutter
 
JRuby and Invokedynamic - Japan JUG 2015
Charles Nutter
 
JRuby 9000 - Taipei Ruby User's Group 2015
Charles Nutter
 
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
Open Source Software Needs You!
Charles Nutter
 
InvokeBinder: Fluent Programming for Method Handles
Charles Nutter
 
Over 9000: JRuby in 2015
Charles Nutter
 
Doing Open Source the Right Way
Charles Nutter
 
JRuby: The Hard Parts
Charles Nutter
 
Bringing Concurrency to Ruby - RubyConf India 2014
Charles Nutter
 
Beyond JVM - YOW! Sydney 2013
Charles Nutter
 
Beyond JVM - YOW! Brisbane 2013
Charles Nutter
 
Beyond JVM - YOW Melbourne 2013
Charles Nutter
 
Down the Rabbit Hole
Charles Nutter
 
The Future of JRuby - Baruco 2013
Charles Nutter
 
High Performance Ruby - E4E Conference 2013
Charles Nutter
 
Invokedynamic in 45 Minutes
Charles Nutter
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
Doc9.....................................
SofiaCollazos
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Software Development Company | KodekX
KodekX
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 

Why JRuby? - RubyConf 2012

  • 2. Who? Thomas Charlie @tom_enebo @headius
  • 4. JRuby is Ruby! * 1.8.7 & 1.9.3 compatibility drop-in replacement * see next slide
  • 5. *caveats • Weak but improving low-level UNIX stuff • No C extension support • Not maintained...off by default in 1.7 • Some features differ or unavailable • ObjectSpace, trace funcs, callcc, fork...
  • 6. JRuby is Ruby ...and then some?
  • 7. Announcing JRuby 1.7.0 • Ruby 1.9.3 compat (--1.8 for 1.8.7) • Java 7 invokedynamic support • Much awesomeness over 1.6.x
  • 8. Getting Started 1. Install a JVM 2. rvm install jruby 3. Profit! % jruby -e ‘puts “wowee”’
  • 10. JRuby Team Charlie Tom Nick Hiro Marcin Nahi Wayne Subbu Douglas Douglas Douglas Contribs Douglas Douglas Douglas Douglas Douglas Other Douglas OpenJDK Android JVMs
  • 11. JRuby JRuby Yoko JVM J. Rose OS (libc, ...)
  • 12. MRI nobu MRI OS (libc, ...)
  • 13. JRuby JRuby Yoko JVM J. Rose OS (libc, ...)
  • 14. We get it for Free! JVM J. Rose Garbage Profiled Native JIT Optimizations Collection Native Tooling Cross Platform Threading
  • 15. Profile: John Rose • JVM Engineer since 1997 • Invented C* Language • JSR 292 lead
  • 16. JVM over time (what if we were lazy?)
  • 17. Go Java Go! 300% for free JRuby 1.0.3 (bm_red_black_tree.rb) 30 22.5 15 7.5 0 Java 1.4 Java 5 Java 6 Java 7
  • 18. Go Java Go! 300% for free JRuby 1.0.3 (bm_red_black_tree.rb) MRI 1.8 30 22.5 15 7.5 0 Java 1.4 Java 5 Java 6 Java 7
  • 21. JVM is everywhere • Unix++, Windows • Exotic platforms: zLinux, OpenVMS, AS/400 • Mobile: Android’s Dalvik, Embedded JVMs
  • 23. Java bytecode == portability
  • 24. actionmailer-javamail, active_documentum, activerecord-jdbc-adapter, activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2- adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord- jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars, akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core, bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin, bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra- jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter, do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop, dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston- rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back, gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass, hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector, iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker, ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify, java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state- machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger, javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3, jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby- httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button, jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback, logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah, mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin, neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r, nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2- kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core, qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge- jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah, redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack- commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty, rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome, rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core- api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon- zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon- deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox- cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming, torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe- javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet- streamer, wrest, wrong, xdojava, xqruby, zookeeper
  • 25. actionmailer-javamail, active_documentum, activerecord-jdbc-adapter, activerecord-jdbcdbf-adapter, activerecord-jdbcderby-adapter, activerecord-jdbch2- adapter, activerecord-jdbchsqldb-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord- jdbcsqlite3-adapter, activerecord-netezza-adapter, activerecord-vertica-adapter, akephalos, akephalos-nerian, akephalos2, akka-actor-jars, akka-remote-jars, akubra_llstore_migrate, Antwrap, async-http-client-jars, atomic, atoulme-Antwrap, autotest-java, bbrowning-deltacloud-client, bbrowning-deltacloud-core, bcrypt-ruby, bee_java, berkeley-db-java-jars, bert, bio-maf, blockenspiel, boc, bond, bosdk, bouncy-castle-java, boxed-geminabox, brute-fuzzy, bryanl-gherkin, bson, buby, buildr, buildr-resolver, buildrizpack, butternut, capistrano-java, capybara-java_script_lint, carrierwave-neo4j, carrierwave_imagevoodoo, cassandra- jars, chrest, cloby, commons-io-jars, concurrently, contextual, coupler, cucumber-java, cucumber-jvm, cuke4duke, cuuid, dm-ldap-adapter, dm-lucene-adapter, do-jdbc_sqlserver, do_derby, do_h2, do_hsqldb, do_jdbc, do_mysql, do_openedge, do_oracle, do_postgres, do_sqlite3, do_sqlserver, doubleshot, dripdrop, dubious, duby, engineyard-visualvm, epall-limelight, errbit_zmq_handler, eurydice, euston, euston-daemons, euston-eventstore, euston-projections, euston- rabbitmq, euston-websites, eventmachine, excemel, faye-websocket, ffi, fig, file-find, fishwife, foreman, forkit, forkjoin, gamelan, gemshit, geoip-jars, get_back, gherkin, glassfish, gravitext-util, gravitext-xmlprod, grizzly, guava-jars, hadoop-find, hashdot-test-daemon, hiredis, hitimes, hope, hostor, hot_bunnies, hourglass, hpricot, http_parser.rb, inline_javascript, iudex, iudex-async-httpclient, iudex-barc, iudex-brutefuzzy-protobuf, iudex-brutefuzzy-service, iudex-char-detector, iudex-core, iudex-da, iudex-filter, iudex-html, iudex-http, iudex-http-test, iudex-httpclient-3, iudex-jetty-httpclient, iudex-rome, iudex-simhash, iudex-worker, ivy-jars, iyyov, jactive_support, java-autotest, java-inline, java2ruby-xmldsig, java_bin, java_inline, java_override, java_properties, java_streamify, java_testing_guff, javabean_xml, javaclass, javaeye4r, javagems, javajake, javaobj, javaobjs, javaobs, javaparse, javasand, javascript-securehash-rails, javascript-state- machine-rails, javascript_auto_include, javascript_eraser, javascript_features, javascript_i18n, javascript_localize, javascript_safe_logger, javascript_util_asset_pack, javascripto, javascripto-rails, jdbc-derby, jdbc-hsqldb, jdbc-jtds, jdbc-openedge, jdbc-openedge-internal, jdbc-postgres, jdbc-sqlite3, No build tools! jedis-jars, jena-jruby, jessica, jettr, jetty, jetty-jsp, jgeoip, jms4r, jpdfer, jrack_handlers, jrtm, jruby-activemq, jruby-akka_jars, jruby-elasticsearch_jars, jruby- httpclient, jruby-launcher, jruby-management, jruby-metrics, jruby-pageant, jruby-vijava, jruby_gc_stats, jruby_sandbox, jruby_threach, jrubyconf-button, jsmetric4java, json, json-jruby, jsound, kb-activerecord-jdbc-adapter, kirk, kyotocabinet-java, ladle, latex-decode, launchy, libnotify, limelight, linecache, logback, logback-jars, looksee, lumix, mack-javascript, markdownj, maven_irb_plugin, metrics-core-jars, metrics-java, mguymon-buildr, mikka, mini_aether, mirah, mirah_model, miso-java, mixology, mm_mq, mongrel, msgpack-idl-java, msgpack-jruby, multimeter, naether, nanoc-javascript-concatenator, neo4j, neo4j-admin, neo4j-advanced, neo4j-community, neo4j-core, neo4j-enterprise, neo4j-spatial, neo4j-will_paginate, neo4j-wrapper, netty-jars, ning-compress-jars, nio4r, nokogiri, nokogiri-fitzsimmons, nokogiri-maven, nosqoop4u, ontomde-demo-java5, ontomde-java, ontomde-java-frontend, ontomde-uml2-java, ontomde-uml2- kbjava, open_nlp, pacer, pacer-dex, pacer-neo4j, pacer-orient, pelops-jars, persvr, pg_array_parser, protobuf-jars, pry, puma, qtjruby-core, qwirk_active_mq_adapter, qwirk_jms_adapter, rabbitmqadmin-cli, ragweed, rails_javascript_helpers, rakejava, rave, rcov, realityforge-jekyll, realityforge- jekylltask, redcar-bundles, redcar-clojure, redcar-filter-through-command, redcar-groovy, redcar-icons, redcar-javamateview, redcar-javascript, redcar-mirah, redcar-svnkit, redcar-xulrunner-win, RedCloth, refinerycms-javascripts, reigns, revo-nokogiri, rika, rjack-async-httpclient, rjack-commons-codec, rjack- commons-dbcp, rjack-commons-dbutils, rjack-commons-pool, rjack-httpclient-3, rjack-httpclient-4, rjack-icu, rjack-jackson, rjack-jdom, rjack-jets3t, rjack-jetty, rjack-jetty-jsp, rjack-jms, rjack-jms-spec, rjack-logback, rjack-lucene, rjack-maven, rjack-mina, rjack-nekohtml, rjack-protobuf, rjack-qpid-client, rjack-rome, rjack-slf4j, rjack-solr, rjack-tarpit, rjack-xerces, rmagick4j, rmodbus, rtm-javatmapi, rtm-majortom, rtm-ontopia, rtm-tinytim, rtm-tmql, rubeus, rubinius-core- api, ruby-blockcache, ruby-debug-base, ruby-maven, ruby2java, rubydoop, rubyjedi-nokogiri_java, scala-inline, scala-library-jars, scriptty, slf4j, slf4j-jars, slyphon- zookeeper, slyphon-zookeeper_jar, smackr, smartimage, SNMP4JR, solr_sail, spiegela-jruby-httpclient, sproutcore, spymemcached, sqldroid, steamcannon- deltacloud-client, steamcannon-deltacloud-core, stilts-stomp-client, supermarket, svm_toolkit, swt, theduke, thick, to-javascript, torquebox-base, torquebox- cache, torquebox-configure, torquebox-container-foundation, torquebox-core, torquebox-messaging, torquebox-messaging-container, torquebox-naming, torquebox-naming-container, torquebox-security, torquebox-server, torquebox-vfs, torquebox-web, twitter4j4r, UDJrb, unageanu-javaclass, unimidi, universe- javascript, url_escape, weakling, webbit-jars, wildnet-jackson, wildnet-netty, wildnet-server, wildsonet-hazelcast, wildsonet-netty, wildsonet-server, wildsonet- streamer, wrest, wrong, xdojava, xqruby, zookeeper
  • 26. Libraries Lucene Neo4j Selenium 47k libraries in Maven Hadoop EHCache JMonkeyEngine Sitemesh
  • 27. Languages/Polyglot Clojure Scala Jython Rhino/Nashorn/ Groovy DynJS (JavaScript) Micro Focus JVM Visual COBOL
  • 28. Polyglot • Use right tool for the right job • Running in the same VM • Another dimension of libraries
  • 29. GC
  • 30. GC Matters • Applications grow over time • Ruby is very object-heavy • Multiprocess multiplies the problem • You will eventually have issues
  • 31. JVM GC • Wide array of options • Many GCs to choose from • Scales up to massive heaps • Best GCs in the world!
  • 32. OpenJDK GCs • Parallel: multi-core stop-the-world • Concurrent: STW young, concurrent old • G1: concurrent young and old • Serial: single-thread STW
  • 33. Object Homogeneity • Everything expressed as JVM objects • Everything shares the same infrastructure • Including extensions, libraries, etc • One GC to rule them all • And one standard memory model
  • 34. gc_demo.rb • Heavy GC, mix of old and young • Steadily growing heap use
  • 35. 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 }
  • 36. Ruby 1.9.3 JRuby 8000 6000 4000 2000 0 GC count
  • 37. Ruby 1.9.3 JRuby 10000 1000 100 10 1 GC count
  • 38. 15 Ruby 1.9.3 JRuby 11.25 7.5 3.75 0 GC time %
  • 39. Ruby 2.0.0 JRuby Time per GC versus heap usage 300ms 225ms Time per GC 150ms 75ms 0ms 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
  • 40. Ruby 2.0.0 JRuby Time per GC versus heap usage :-( :-( User Unhappiness :-/ :-| :-) 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
  • 41. Ruby 2.0.0 4,000 3,000 Time Per GC (ms) 2,000 1,000 0 0M 1,250M 2,500M 3,750M 5,000M Heap Size
  • 42. Findings • Lower, more uniform GC times • Reduced or eliminated pauses • Very large heaps are no problem • Predictable, consistent experience
  • 44. Real Parallellism • Ruby thread = JVM thread = native thread • One process can use all cores • One server can handle all requests
  • 45. require 'benchmark' ary = (1..1000000).to_a loop {   puts Benchmark.measure {     10.times {       ary.each {|i|}     }   } }
  • 46. require 'benchmark' ary = (1..1000000).to_a loop {   puts Benchmark.measure {     (1..10).map {       Thread.new {         ary.each {|i|}       }     }.map(&:join)   } }
  • 49. Ruby 1.9 Ruby 1.9 unthreaded threaded
  • 50. Ruby 1.9 Ruby 1.9 unthreaded threaded JRuby unthreaded
  • 51. Ruby 1.9 Ruby 1.9 unthreaded threaded JRuby JRuby unthreaded threaded
  • 52. threaded_reverse Per-iteration time versus thread count 0.8s 0.65s 0.5s 0.35s 0.2s one thread two threads three threads four threads
  • 53. Nonlinear? • More work means more objects • Allocation/GC needs memory bandwidth • No different from multi-process
  • 55. Tools
  • 56. Profiling • Java profilers • VisualVM,YourKit, NetBeans, JXInsight • jruby [--profile | --profile.graph] • jruby -Xreify.classes=true • JVM command-line profilers
  • 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. VisualVM • CPU, memory, thread monitoring • CPU and memory profiling • VisualGC • Heap analysis
  • 67. JavaFX straight port Simple Clock
  • 68. @minute_hand = Path.new.tap do |mh| Draw minute hand mh.setFill(Color::BLACK) mh.getElements.add MoveTo.new(4, -4) mh.getElements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.getElements.add LineTo.new(0, -radius) mh.getTransforms.add Rotate.new end Implement Java Event class Refresher include EventHandler handler def handle(event); event.source.refresh; end end refresh timeline every 1s Timeline.new.tap do |time| time.setCycleCount Timeline::INDEFINITE time.getKeyFrames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end
  • 69. getFooBar -> fooBar @minute_hand = Path.new.tap do |mh| mh.setFill(Color::BLACK) was getElements mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end was getTransforms class Refresher include EventHandler def handle(event); event.source.refresh; end end Timeline.new.tap do |time| time.setCycleCount Timeline::INDEFINITE time.keyFrames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end was getKeyFrames
  • 70. setFoo(a) -> foo = a @minute_hand = Path.new.tap do |mh| mh.fill = Color::BLACK was setFill mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end class Refresher include EventHandler def handle(event); event.source.refresh; end end Timeline.new.tap do |time| was setCycleCount time.cycleCount = Timeline::INDEFINITE time.keyFrames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end
  • 71. camelCase -> camel_case @minute_hand = Path.new.tap do |mh| mh.fill = Color::BLACK mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end class Refresher include EventHandler def handle(event); event.source.refresh; end end Timeline.new.tap do |time| was cycleCount time.cycle_count = Timeline::INDEFINITE time.key_frames.add(Keyframe.new(Duration.millis(1000)), Refresher.new) time.play end was keyFrames
  • 72. Procs as interfaces @minute_hand = Path.new.tap do |mh| mh.fill = Color::BLACK mh.elements.add MoveTo.new(4, -4) mh.elements.add ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements.add LineTo.new(0, -radius) mh.transforms.add Rotate.new end No more extra class Timeline.new.tap do |time| time.cycle_count = Timeline::INDEFINITE time.key_frames.add Keyframe.new(Duration.millis(1000)) {refresh} time.play end
  • 73. Common Adornments ‘add’ becomes ‘<<‘ @minute_hand = Path.new.tap do |mh| mh.fill = Color::BLACK mh.elements << MoveTo.new(4, -4) mh.elements << ArcTo.new(-1, -1, 0, -4, -4, false, false) mh.elements << LineTo.new(0, -radius) mh.transforms << Rotate.new end Timeline.new.tap do |time| time.cycle_count = Timeline::INDEFINITE time.key_frames << Keyframe.new(Duration.millis(1000)) {refresh} time.play end
  • 74. Purugin • Minecraft scripting in JRuby • Clean and simple DSL • Purogo: LOGO for Minecraft
  • 75. turtle("four-sided triangle") do |*args|   dim = (args[0] || 5).to_i   block_type = (args[1] || :stone).to_sym   layer do     4.times do |i|       forward dim       turnleft 90     end   end      pivot do     block :none     forward 1     turnleft 90     forward 1     turnup 90     forward 1     turndown 90     turnright 90     block block_type   end   block block_type   (1...dim).step(2).to_a.reverse.each do |i|     dim = i     layer     pivot   end end
  • 79. Native Extensions Suck “Look, nobody enjoys shooting penguins, but if you have to shoot penguins, well, you might as well enjoy it.” - Free Waterfall Sr.
  • 80. Flowchart of Shame Can I write it in Ruby? Script Java? no yes no Does it need Can I use FFI? to be n times faster? no no Native Extension
  • 81. Java Native Extensions • Written in Java • Have same performance as Java • Use same GC as JRuby • First Class Citizens
  • 83. Go Java Go! 300% for free JRuby 1.0.3 (bm_red_black_tree.rb) 30 22.5 15 7.5 0 Java 1.4 Java 5 Java 6 Java 7
  • 84. Go JRuby Go! OpenJDK 8 (bm_red_black_tree.rb) 8 6 4 2 0 1.0.3 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 85. Severe gains??? OpenJDK 8 (bm_red_black_tree.rb) 9 Severe perf bottleneck(s) 6.75 4.5 2.25 0 1.0.3 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 86. 1.0.3 & red_black_tree -J-verbose:gc [GC (Allocation Failure) 223608K->96408K(330752K), 0.0159780 secs] [GC (Allocation Failure) 208920K->100792K(335168K), 0.0157550 secs] [GC (Allocation Failure) 213304K->105144K(332160K), 0.0181010 secs] 8.1s [GC (Allocation Failure) 205112K->108920K(334400K), 0.0187580 secs] [GC (Allocation Failure) 208888K->112712K(329152K), 0.0154440 secs] +28 more [GC (Allocation Failure) 313780K->199892K(339072K), 0.0142010 secs] [GC (Allocation Failure) 318420K->204420K(331520K), 0.0175690 secs] 8.4s [GC (Allocation Failure) 306948K->208316K(335680K), 0.0188120 secs] [Full GC (Ergonomics) 208316K->54991K(352256K), 0.2709750 secs] [GC (Allocation Failure) 157519K->58959K(349248K), 0.0120840 secs] +28 more Moar Objects!
  • 87. 1.7.0 & red_black_tree -J-verbose:gc [GC (Allocation Failure) 155729K->39697K(207296K), 0.0072730 secs] 0.963s [GC (Allocation Failure) 160785K->40657K(208320K), 0.0108620 secs] 0.968s [GC (Allocation Failure) 161745K->41649K(210112K), 0.0083760 secs] 0.968s [GC (Allocation Failure) 166193K->39729K(210688K), 0.0070670 secs] 0.99s
  • 88. OpenJDK 8 (bm_red_black_tree.rb) 3 2.25 1.5 0.75 0 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 89. OpenJDK 8 (bm_red_black_tree.rb) 3 JVM Feature! 2.25 1.5 0.75 0 1.1.6 1.4.0 1.5.6 1.6.8 1.7.0
  • 90. Performance • JRuby compiles Ruby to JVM bytecode • JVM compiles bytecode to native • Best JIT technology in the world • Getting even better with invokedynamic
  • 91. How to Optimize Ruby • Do less work • Reduce dispatch and call overhead • Reduce memory overhead • Find static patterns • Profile running code • Emit optimized version with guards
  • 92. JVM Optimizations • Profiling • Watch code, optimize hottest paths • Inlining • Combine code, optimize as a whole • Escape analysis • Eliminate transient objects
  • 93. def foo; Object.new; end def invoker; foo; end i = 0 while i < 10000   invoker   i+=1 end
  • 94. Inline foo into invoker def invoker; Object.new; end i = 0 while i < 10000   invoker   i+=1 end
  • 95. Inline invoker into loop i = 0 while i < 10000   Object.new   i+=1 end
  • 96. Object is transient i = 0 while i < 10000   i+=1 end
  • 98. Variable i is never read
  • 99. InvokeDynamic • Java 7+ feature • Allows us to teach JVM about Ruby • Dynamic calls can inline • Constants become truly constant • JVM’s best optimizations can work
  • 101. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end
  • 102. $ jruby -J-XX:+UnlockDiagnosticVMOptions -J-XX:+PrintInlining -J-XX:+PrintCompilation script.rb 79 1 b java.lang.String::hashCode (55 bytes) 109 2 b java.util.Properties$LineReader::readLine (452 bytes) @ 48 java.io.Reader::read (9 bytes) never executed @ 62 java.io.FilterInputStream::read (9 bytes) @ 303 java.lang.System::arraycopy (0 bytes) (intrinsic) @ 388 java.io.Reader::read (9 bytes) never executed ....
  • 103. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 104. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 105. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 106. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 107. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 108. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 109. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 110. def foo; 1; end def invoker; foo; end N.times do i = 0 while i < 10000    invoker    i+=1 end end 3321 190 b ruby.__dash_e__::block_0$RUBY$__file__ (83 bytes) @ 6 org.jruby.RubyFixnum::op_lt (22 bytes) inline (hot) @ 66 org.jruby.RubyBasicObject::isTrue (15 bytes) inline (hot) @ 6 ruby.__dash_e__::method__1$RUBY$invoker (9 bytes) inline (hot) @ 6 ruby.__dash_e__::method__0$RUBY$foo (7 bytes) inline (hot) @ 5 org.jruby.RubyFixnum::op_plus_one (31 bytes) inline (hot)
  • 113. JRuby/Java 6 JRuby/Java 7
  • 114. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 3.75 2.5 1.25 0 base64 richards neural mandelbrot redblack
  • 115. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 3.75 2.5 1.914 1.806 1.538 1.565 1.25 1.346 0 base64 richards neural mandelbrot redblack
  • 116. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 4.226 4.32 3.75 3.66 3.44 2.5 2.658 1.914 1.806 1.538 1.565 1.25 1.346 0 base64 richards neural mandelbrot redblack
  • 117. smooth_sort # Original Author: Keith Schwarz ([email protected]) # # Translated to Ruby by Chuck Remes (chuckremes on github) # # An implementation of Dijkstra's Smoothsort algorithm, a modification of # heapsort that runs in O(n lg n) in the worst case, but O(n) if the data # are already sorted. For more information about how this algorithm works # and some of the details necessary for its proper operation, please see # # http://www.keithschwarz.com/smoothsort/
  • 118. Ruby 1.8.7 Ruby 1.9.3 Ruby 2.0.0 JRuby 100000 75000 50000 25000 19590.7 11439 4750 0 Iterations per second
  • 123. 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! • JRuby BOF in Room C at 6:30PM
  • 126. Thank you! • @headius • jruby.org • torquebox.org

Editor's Notes