Aloha RubyConf 2012 - JRuby

3,144 views

Published on

Talk on "Why JRuby" for Aloha RubyConf 2012.

Published in: Technology
0 Comments
11 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,144
On SlideShare
0
From Embeds
0
Number of Embeds
59
Actions
Shares
0
Downloads
29
Comments
0
Likes
11
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • java developers know what an app server is\n
  • \n
  • \n
  • redeploy\n
  • TorqueBox brings that all together\norange is ruby, red is java\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Aloha RubyConf 2012 - JRuby

    1. 1. Why JRuby?
    2. 2. Me• Charles Oliver Nutter • @headius• Java developer since 1996• JRuby developer since 2006• Red Hat / JBoss polyglot group
    3. 3. What is JRuby?
    4. 4. 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*
    5. 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. 6. JRuby 1.7• Ruby 1.9.3 mode by default • Many 1.9 compat fixes• Numerous perf improvements • Java 7 invokedynamic support• Beginning of new optimizing compiler
    7. 7. Getting Started• Need a JVM...• rvm install jruby • rvm install jruby-1.7.0-RC1• Download manually • Unpack, edit PATH, done
    8. 8. Try it Out
    9. 9. def fractal_flipflop w, h = 44, 54 c = 7 + 42 * w a = [0] * w * h g = d = 0 f = proc do |n| a[c] += 1 o = a.map {|z| " :#"[z, 1] * 2 }.join.scan(/.{#{w * 2}}/) puts "f" + o.map {|l| l.rstrip }.join("n") d += 1 - 2 * ((g ^= 1 << n) >> n) c += [1, w, -1, -w][d %= 4] end 1024.times do !!(!!(!!(!!(!!(!!(!!(!!(!!(true... f[0])...f[1])...f[2])... f[3])...f[4])...f[5])... f[6])...f[7])...f[8]) endend
    10. 10. def fractal_flipflop w, h = 44, 54 c = 7 + 42 * w a = [0] * w * h g = d = 0 f = proc do |n| a[c] += 1 o = a.map {|z| " :#"[z, 1] * 2 }.join.scan(/.{#{w * 2}}/) puts "f" + o.map {|l| l.rstrip }.join("n") d += 1 - 2 * ((g ^= 1 << n) >> n) c += [1, w, -1, -w][d %= 4] end 1024.times do !!(!!(!!(!!(!!(!!(!!(!!(!!(true... f[0])...f[1])...f[2])... f[3])...f[4])...f[5])... f[6])...f[7])...f[8]) endend
    11. 11. JRuby is the best* Ruby runtime
    12. 12. The Team
    13. 13. JRuby Team
    14. 14. JRuby Team Charlie
    15. 15. JRuby Team Charlie TomNick Hiro Marcin Nahi Wayne Subbu Douglas Douglas Douglas Contribs
    16. 16. JRuby Team Charlie TomNick Hiro Marcin Nahi Wayne Subbu Douglas Douglas Douglas Contribs Douglas Douglas Douglas Douglas Douglas Douglas Douglas Other Douglas OpenJDK Android J9 JVMs
    17. 17. JRuby Structure JRuby Bytecode Core JavaParser JIT Classes Integ JVM NativeThreads GC C API JIT
    18. 18. JRuby Structure JRuby Bytecode Core Java Parser JIT Classes IntegJRuby team can focus on implementing JRuby.
    19. 19. JRuby Team Doesn’t Have to Work On*• Memory allocation • Native JIT• Garbage collectors • Tooling• Native threading • Server environments• Cross-platform • Native extensions• Mobile/Embedded VMs
    20. 20. We could stop workingon JRuby and it wouldcontinue to get faster.
    21. 21. Platforms
    22. 22. Systems• Best Ruby on Windows?• Exotic platforms: zLinux, OpenVMS, AS/400• Android’s Dalvik• Embedded JVMs
    23. 23. 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
    24. 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- No build tools, no native exts required! 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. 25. Servers• Any Java server can host Ruby• Trinidad • Ruby-style CLI server atop Tomcat• Torquebox • Full Ruby stack atop JBossAS
    26. 26. Ruby App Sinatra Rails Rack Passenger/Thin Apache/Nginx
    27. 27. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Resque/DelayedJob Apache/Nginx
    28. 28. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/DelayedJob Apache/Nginx crond
    29. 29. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/DelayedJob Apache/Nginx crond Daemons god/monit
    30. 30. TorqueBox ASSinatra Rails Rack Tasks Procs Jobs Daemons Web Messaging Scheduling Services JBoss AS Clustering Load Balancing HA
    31. 31. Torquebox• Rack-compatible • Server management• Database connectivity • Clustering• Background daemons • In and out-process cache• Scheduled jobs • Web sockets• Messaging • Authentication• Asynchronous tasks • XA Transactions
    32. 32. Torquebox• Rack-compatible • Server management• Database connectivity • Clustering• All R Background daemons • In and out-process cache• Scheduled jobs uby • Web sockets• Messaging APIs • Authentication• Asynchronous tasks • ! XA Transactions
    33. 33. Ruby-friendly ConfigTorqueBox.configure do  ruby do ruby:    version "1.9"   version: 1.9    compile_mode "off"   compile_mode: off    debug false   debug: false    interactive true   interactive: true    profile_api true   profile_api: true  endend
    34. 34. Messaging application:TorqueBox.configure do   ..  ... queues:  queue /queues/my_app_queue   /queues/my_app_queue:  topic /queues/my_app_topicend topics:   /queues/my_app_topic:
    35. 35. Messagingqueue = fetch(/queues/foo)queue.publish "A text message"topic = fetch(/topics/foo)topic.publish "A text message"queue = TorqueBox::Messaging::Queue.new(/queues/foo)message = queue.receivetopic = TorqueBox::Messaging::Topic.new(/topics/foo)message = topic.receive
    36. 36. Libraries
    37. 37. Libraries• 340k versioned jars in Maven central • Compare to 35k gems in RubyGems.org• Vast majority have no native code• All usable from JRuby
    38. 38. JavaFX• Scene graph + optimized graphics• Normal Java library now • R.I.P. JavaFX Script• jrubyfx, other projects to wrap it
    39. 39.     @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     @hour_hand = Path.new.tap do |hh|      hh.fill = Color::BLACK      hh.elements << MoveTo.new(4, -4)      hh.elements << ArcTo.new(-1, -1, 0, -4, -4, false, false)      hh.elements << LineTo.new(0, -radius/4*3)      hh.transforms << Rotate.new    end
    40. 40. Purugin• Minecraft scripting in JRuby• Clean and simple DSL• Purogo: LOGO for Minecraft
    41. 41. 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  endend
    42. 42. Threepence• Ruby APIs atop Ardor3D library • Various games atop Ardor3D• All-in-one clone from Github • Linux, OS X, Windows, Solaris provided
    43. 43. require example_baseclass Box < ExampleBase  def initialize    super("Box Example")  end  def init_application    root.layout do      cull_state :back      skybox(:sky, 500, 500, 500, images/skybox/blue)      node(:spinning) do behavior :rotating, Vector3(1, 1, 0.5), 50 box(:left_box, 1, 1, 1) do behavior :rotating, Vector3(0.5, 1, 1), 50 at 0, 0, -3 texture "images/ardor3d_white_256.jpg" end.duplicate_as(:right_box) do at 0, 0, 3" end      end    end  endendBox.start
    44. 44. GC
    45. 45. GC Matters• Applications grow over time• Ruby is very object-heavy• Multicore MRI multiplies the problem• You will eventually have issues
    46. 46. JVM GC• Wide array of options• Many GCs to choose from• Scales up to massive heaps• Best GCs in the world!
    47. 47. OpenJDK GCs• Parallel: multi-core stop-the-world• Concurrent: STW young, concurrent old• G1: concurrent young and old• Serial: single-thread STW
    48. 48. gc_demo1.rb• Heavy GC, mix of old and young• Steadily growing heap use
    49. 49. class Simple  attr_accessor :nextendtop = Simple.newputs Benchmark.measure {  outer = 10  total = 100000  per = 100  outer.times do    total.times do      per.times { Simple.new }      s = Simple.new      top.next = s      top = s    end  end}
    50. 50. Ruby 1.9.3 JRuby8000600040002000 0 GC count
    51. 51. Ruby 1.9.3 JRuby10000 1000 100 10 1 GC count
    52. 52. 15 Ruby 1.9.3 JRuby11.25 7.5 3.75 0 GC time %
    53. 53. Ruby 2.0.0 JRuby Time per GC versus heap usage300ms225ms150ms75ms 0ms 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
    54. 54. gc_demo2.rb• Frequent GC, all young objects• Steadily growing heap use
    55. 55. 10.times do  old_ary = []  10000.times do    old_ary << foo    new_ary = []    100000.times do      new_ary << bar    end  end  puts "looped"end
    56. 56. Ruby 1.9.3 JRuby5000375025001250 0 GC time (ms)
    57. 57. JRuby (Concurrent) Ruby 2.0.0 World-stopping GC pause times 0.3s 0.225sPause time 0.15s 0.075s 0s 0 5 10 15 20 Seconds since start
    58. 58. JRuby (Concurrent) Ruby 2.0.0 World-stopping GC pause times 0.3s im es 0.225s useT PaPause time 0.15s 0.075s 0s 0 5 10 15 20 Seconds since start
    59. 59. JRuby (Concurrent) Ruby 2.0.0 World-stopping GC pause times 0.3s im es 0.225s useT PaPause time 0.15s Use r Ha ppi 0.075s nes s :- ( 0s 0 5 10 15 20 Seconds since start
    60. 60. Findings• Lower, more uniform individual GC time• Lower overall GC time• Lower application pause times• More predictable, consistent apps
    61. 61. Threads
    62. 62. Real Parallellism• Ruby thread = JVM thread = native thread• One process can use all cores• One server can handle all requests
    63. 63. require benchmarkary = (1..1000000).to_aloop {  puts Benchmark.measure {    10.times {      ary.each {|i|}    }  }}
    64. 64. require benchmarkary = (1..1000000).to_aloop {  puts Benchmark.measure {    (1..10).map {      Thread.new {        ary.each {|i|}      }    }.map(&:join)  }}
    65. 65. Ruby 1.9unthreaded
    66. 66. Ruby 1.9 Ruby 1.9unthreaded threaded
    67. 67. Ruby 1.9 Ruby 1.9unthreaded threaded JRubyunthreaded
    68. 68. Ruby 1.9 Ruby 1.9unthreaded threaded JRuby JRubyunthreaded threaded
    69. 69. threaded_reverse Per-iteration time versus thread count 0.8s0.65s 0.5s0.35s 0.2s one thread two threads three threads four threads
    70. 70. Nonlinear?• More work means more objects• More objects needs memory bandwidth• No different from multi-process
    71. 71. Tools
    72. 72. Profiling• Java profilers • VisualVM,YourKit, NetBeans, JXInsight• jruby [--profile | --profile.graph]• jruby -Xreify.classes=true• JVM command-line profilers
    73. 73. 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
    74. 74. VisualVM• CPU, memory, thread monitoring• CPU and memory profiling• VisualGC• Heap analysis
    75. 75. Performance
    76. 76. Performance• JRuby compiles Ruby to JVM bytecode• JVM compiles bytecode to native• Best JIT technology in the world• Getting even better with invokedynamic
    77. 77. def foo barenddef bar baz foo bar bazenddef baz # ...end
    78. 78. JRuby on Java 5/6def foo barenddef bar JRuby JRuby baz foo call bar call bazend logic logicdef baz # ...end Kills many JVM optimizations
    79. 79. JRuby on Java 7def foo bar X Xenddef bar JRuby JRuby baz foo call bar call bazend logic logicdef baz # ...end Dynamic call logic built into JVM
    80. 80. JRuby on Java 7def foo barenddef bar baz foo bar bazenddef baz # ...end Straight through dispatch path
    81. 81. JRuby on Java 7def foo barenddef bar baz foo bar bazenddef baz # ...end Optimizations (like inlining) can happen!
    82. 82. def foo; 1; end def invoker; foo; end i = 0 while i < 10000   invoker   i+=1 end  0x00000001060a1be0: mov %eax,-0x14000(%rsp)  0x00000001060a1be7: push %rbp  0x00000001060a1be8: sub $0x30,%rsp  0x00000001060a1bec: mov 0x8(%rcx),%r10d  0x00000001060a1bf0: cmp $0xfb7aedc9,%r10d  0x00000001060a1bf7: jne 0x00000001060a1c39  0x00000001060a1bf9: mov %rcx,%r10  0x00000001060a1bfc: mov 0x10(%r10),%ebp  0x00000001060a1c00: cmp $0xfed77602,%ebp  0x00000001060a1c06: jne 0x00000001060a1c1e  0x00000001060a1c08: movabs $0x7f6bf4bb0,%rax  0x00000001060a1c12: add $0x30,%rsp  0x00000001060a1c16: pop %rbp  0x00000001060a1c17: test %eax,-0xec3c1d(%rip)  0x00000001060a1c1d: retq
    83. 83. def invoker; 1; end i = 0 while i < 10000   invoker   i+=1 end  0x00000001060a1be0: mov %eax,-0x14000(%rsp)  0x00000001060a1be7: push %rbp  0x00000001060a1be8: sub $0x30,%rsp  0x00000001060a1bec: mov 0x8(%rcx),%r10d  0x00000001060a1bf0: cmp $0xfb7aedc9,%r10d  0x00000001060a1bf7: jne 0x00000001060a1c39  0x00000001060a1bf9: mov %rcx,%r10  0x00000001060a1bfc: mov 0x10(%r10),%ebp  0x00000001060a1c00: cmp $0xfed77602,%ebp  0x00000001060a1c06: jne 0x00000001060a1c1e  0x00000001060a1c08: movabs $0x7f6bf4bb0,%rax  0x00000001060a1c12: add $0x30,%rsp  0x00000001060a1c16: pop %rbp  0x00000001060a1c17: test %eax,-0xec3c1d(%rip)  0x00000001060a1c1d: retq
    84. 84. i = 0 while i < 10000   1   i+=1 end  0x00000001060a1be0: mov %eax,-0x14000(%rsp)  0x00000001060a1be7: push %rbp  0x00000001060a1be8: sub $0x30,%rsp  0x00000001060a1bec: mov 0x8(%rcx),%r10d  0x00000001060a1bf0: cmp $0xfb7aedc9,%r10d  0x00000001060a1bf7: jne 0x00000001060a1c39  0x00000001060a1bf9: mov %rcx,%r10  0x00000001060a1bfc: mov 0x10(%r10),%ebp  0x00000001060a1c00: cmp $0xfed77602,%ebp  0x00000001060a1c06: jne 0x00000001060a1c1e  0x00000001060a1c08: movabs $0x7f6bf4bb0,%rax  0x00000001060a1c12: add $0x30,%rsp  0x00000001060a1c16: pop %rbp  0x00000001060a1c17: test %eax,-0xec3c1d(%rip)  0x00000001060a1c1d: retq
    85. 85. i = 0 while i < 10000   i+=1 end  0x00000001060a1be0: mov %eax,-0x14000(%rsp)  0x00000001060a1be7: push %rbp  0x00000001060a1be8: sub $0x30,%rsp  0x00000001060a1bec: mov 0x8(%rcx),%r10d  0x00000001060a1bf0: cmp $0xfb7aedc9,%r10d  0x00000001060a1bf7: jne 0x00000001060a1c39  0x00000001060a1bf9: mov %rcx,%r10  0x00000001060a1bfc: mov 0x10(%r10),%ebp  0x00000001060a1c00: cmp $0xfed77602,%ebp  0x00000001060a1c06: jne 0x00000001060a1c1e  0x00000001060a1c08: movabs $0x7f6bf4bb0,%rax  0x00000001060a1c12: add $0x30,%rsp  0x00000001060a1c16: pop %rbp  0x00000001060a1c17: test %eax,-0xec3c1d(%rip)  0x00000001060a1c1d: retq
    86. 86.   0x00000001060a1be0: mov %eax,-0x14000(%rsp)  0x00000001060a1be7: push %rbp  0x00000001060a1be8: sub $0x30,%rsp  0x00000001060a1bec: mov 0x8(%rcx),%r10d  0x00000001060a1bf0: cmp $0xfb7aedc9,%r10d  0x00000001060a1bf7: jne 0x00000001060a1c39  0x00000001060a1bf9: mov %rcx,%r10  0x00000001060a1bfc: mov 0x10(%r10),%ebp  0x00000001060a1c00: cmp $0xfed77602,%ebp  0x00000001060a1c06: jne 0x00000001060a1c1e  0x00000001060a1c08: movabs $0x7f6bf4bb0,%rax  0x00000001060a1c12: add $0x30,%rsp  0x00000001060a1c16: pop %rbp  0x00000001060a1c17: test %eax,-0xec3c1d(%rip)  0x00000001060a1c1d: retq
    87. 87. JRuby/Java 6 JRuby/Java 7
    88. 88. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.51.25 0 base64 richards neural mandelbrot redblack
    89. 89. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.5 1.914 1.806 1.538 1.5651.25 1.346 0 base64 richards neural mandelbrot redblack
    90. 90. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 4.226 4.323.75 3.66 3.44 2.5 2.658 1.914 1.806 1.538 1.5651.25 1.346 0 base64 richards neural mandelbrot redblack
    91. 91. smooth_sort# Original Author: Keith Schwarz (htiek@cs.stanford.edu)## Translated to Ruby by Chuck Remes (chuckremes on github)## An implementation of Dijkstras 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/
    92. 92. Ruby 1.9.3 JRuby Rubinius MacRuby Ruby 1.8.7100000 75000 50000 90593 57215 25000 18376 11439 4750 0 Iterations per second
    93. 93. And Rails?
    94. 94. 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!
    95. 95. JRUBY BOOK
    96. 96. Thank you!• @headius• jruby.org• torquebox.org

    ×