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

JRuby - The enterprise view

JRuby - The enterprise view

JRuby is often portrayed as the Ruby with brilliant Garbage Collection and native threads but poor startup time and large memory overhead. But how can JRuby really help you in a project, especially when you deal with large corporations that live in the Java world.

Leif Gensert

November 13, 2013
Tweet

More Decks by Leif Gensert

Other Decks in Programming

Transcript

  1. The enterprise
    view

    View Slide

  2. One of the best GCs in the world
    Native Threading
    Profiled Optimizations
    Native JIT
    True Parallelism
    (slow startup time)

    View Slide

  3. View Slide

  4. Recap
    “The Java World”

    View Slide

  5. Let me tell you a story

    View Slide

  6. The Migration

    View Slide

  7. Java Database Connectivity
    (JDBC)

    View Slide

  8. require 'java'
    !
    java_import 'oracle.jdbc.OracleDriver'
    java_import 'java.sql.DriverManager'
    !
    class OracleConnection
    !
    def initialize (user, passwd, url)
    oradriver = OracleDriver.new
    !
    DriverManager.registerDriver oradriver
    @conn = DriverManager.get_connection url, user, passwd
    end
    !
    def create_statement()
    @conn.create_statement
    end
    !
    def prepare_statement(sql)
    @conn.prepare_statement sql
    end
    !
    def commit()
    @conn.commit
    end
    !
    end
    The Oracle Way
    stmnt = conn.create_statement
    result_set = stmnt.execute_query 'select * from users'
    !
    while result_set.next
    result_set.get_object('ID')
    end

    View Slide

  9. require 'java'
    !
    java_import 'oracle.jdbc.OracleDriver'
    java_import 'java.sql.DriverManager'
    require 'sequel'
    !
    class OracleConnection
    def initialize (user, passwd, host, port, sid)
    url = "jdbc:oracle:thin:#{user}/#{passwd}@#{host}:#{port}:#{sid}"
    @client = Sequel.connect url
    end
    !
    def query sql
    @client.fetch(sql)
    end
    end
    The Sequel Way
    client = OracleConnection.new('...')
    client.query('select * from users').each do |row|
    # {
    # id: 1,
    # first_name: 'Harry',
    # last_name: 'Hurtig',
    # user_name: 'hhurtig',
    # }
    end

    View Slide

  10. View Slide

  11. $ which java
    /usr/jdk/jdk1.6.0_51/bin/java
    !
    $ wget http://jruby.org/.../jruby-bin-1.7.6.tar.gz
    $ tar zxf jruby-bin-1.7.6.tar.gz -C ~/jruby
    !
    $ export PATH=~/jruby/bin:$PATH
    !
    $ gem install bundler
    $ bundle install

    View Slide

  12. Other Examples

    View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. Conclusion
    • Not only GC and Native Threads
    • Take advantage of “Java is everywhere”
    • Embrace the JVM ecosystem

    View Slide

  17. Attribution
    • http://www.flickr.com/photos/tf28/4444660417 by TF28 ❘ tfaltings.de

    • http://www.flickr.com/photos/pedrosz/3993734789 by szeke

    • http://www.flickr.com/photos/nzdave/347532488 by (nz)dave

    • http://www.flickr.com/photos/cgranycome/9954708374 by CarolineG2011

    • http://www.flickr.com/photos/digitalnc/8233509306 by North Carolina Digital Heritage Center

    • http://en.wikipedia.org/wiki/File:Java_virtual_machine_architecture.svg by Wikimedia Commons

    • http://www.flickr.com/photos/mdavidford/8650284288 by mdavidford

    • http://www.flickr.com/photos/apollo1981/1478327767 by apollo1981

    • http://www.flickr.com/photos/yggg/287485592 by [email protected]จ๪۩ࣾ

    • http://www.flickr.com/photos/kakutani/8281245690/ by kakutani

    • http://www.flickr.com/photos/barbro2009/5625148914 by Barbro_Uppsala

    View Slide