SlideShare une entreprise Scribd logo
1  sur  37
Introduction to JRuby
        Anthony Juckel
      ajuckel@gmail.com
           @ajuckel
What is Ruby?
• Dynamic/duck-typed language
• Strongly object oriented
• Open class definitions
• Closures, blocks, and generators, oh my!
What is JRuby?
What is JRuby?
• JRuby == Ruby
What is JRuby?
• JRuby == Ruby
• JRuby != Ruby
What is JRuby?
• JRuby == Ruby
• JRuby != Ruby
• JRuby == Ruby++
How to install it?
• Download from jruby.org
• Install via rvm (but not on this wifi)
What can I do with it?
• Run Ruby code (1.8 or 1.9)
• Access Java libraries from Ruby
• Embed Ruby within a Java application
Lab 1: Install it!
• $ jruby -e ‘puts “Hello, World!”’
• $ jruby hello.rb
• $ jruby --1.9 hello.rb
• $ jirb
• $ jruby --1.9 -S irb
• $ JRUBY_OPTS=”--1.9” jirb
RubyGems
• Gems are units of software reuse in the
  Ruby world
• Most Gems will work the same in JRuby as
  in MRI
• Gems with native code _may_ work, but
  seek alternatives
RubyGems
• Gems can install library files
 • $ gem install json
 • require ‘json’
• Gems can install scripts
 • $ gem install rspec
 • $ jruby --1.9 -S rspec
RubyGems
• Some gems are only of interest on JRuby
 • jruby-openssl
 • activerecord-jdbc-adapter
RubyGems
• Others have JRuby-specific versions
 • nokogiri
   • Uses libxml on MRI
   • Uses Java XML libraries on JRuby
Lab 2: Gems
• $ gem search -r [gem]   • jruby-openssl
• $ gem install [gem]     • rspec
• $ gem list              • json
• $ gem rdoc              • bundler
• $ gem server            • $ cd lab02
                          • $ rspec
Launch Time
• Yes, it can be a problem
• MRI: Quick to start, speed remains constant
• JVM: Slow to start, faster as hotspots are
  optimized
Launch Time
• What to do about it?
 • Tweak startup options to make JVM
    startup as fast as possible
Launch Time
• JVM Options (prefixed with -J with jruby)
 • -client (-J-client)
 • -XX:+TieredCompilation
 • -Xshare:dump / -Xshare:on
Launch Time
• JRuby Options
 • -X-C (turn off compilation)
 • --ng-server / --ng
    • --ng will get faster after several
       executions while the JVM optimizes
Launch Time
           ITERATIONS=1000 rspec

1000
                                          1.9.3
                                          JRuby
100                                       JRuby -X-C
                                          JRuby NailGun
 10


   1


 0.1
    1000           100000      10000000
Lab 3: Try it out
• -J-client
• -J-XX:+TieredCompilation
• -J-Xshare:on
• -X-C (turn off compilation)
• --ng-server / --ng
Launch Time (cont.)
• Can be improved, but for small tasks
  cannot (yet?) match MRI
• What options are left?
 • Guard
 • Spork
Launch Time (cont.)
• Iterate using MRI
  • Quickly verify small changes
• Integrate using JRuby
  • Less frequent
  • May have longer test suites, perhaps more
    work, can afford to pay the start up cost
ActiveRecord
• An Object-Relational Mapping (ORM)
  library
• Developed as part of Rails
• Maps database data to Ruby classes
ActiveRecord
• activerecord: Core functionality
• activerecord-*-adapter: Database-specific
  adapter layer
ActiveRecord
• MRI’s activerecord-*-adapters use native
  database libraries.
• JRuby can use JDBC drivers
• Must have JDBC adapter on classpath
• activerecord-jdbc*-adapters
Lab 4: ActiveRecord
• $ gem install activerecord-jdbc-adapter
•   $ gem install activerecord-jdbcpostgresql-adapter

•   $ gem install activerecord-jdbcsqlite3-adapter

•   $ gem install activerecord-derby-adapter
Converting Rails App
• Rails itself (aside from ActiveRecord) is
  very compatible with JRuby
• Gems used in any given project may or may
  not be.
• jruby-lint can help identify potential issues.
Converting Rails App
• What are some known issues?
 • Some ObjectSpace methods disabled by
    default
 • Native code use
 • Kernel#fork / backtick operator / system
    usage
Lab 5: Convert an App
• $ cd graphy # Rails app targeting MRI 1.9.3
• If you’ve got MRI installed, look at current
  app
  • bundle install
  • rake db:create db:migrate db:seed
  • rails s
Lab 5: Convert an App
• $ jrlint
• Update Gemfile
 • :platforms => :jruby
   • activerecord-jdbc*-adapter
 • :platforms => :ruby
  • pg, sqlite3
Lab 5: Convert an App
• After performing the updates, test the app
  in JRuby
• Also test the app in MRI, if available
 • Having dependencies properly scoped
    should allow you to execute the app in
    either environment
Lab 5: Convert an App
• Have an app along with you? Try
  converting it now!
• Install/Run jrlint
• Update Gemfile (if necessary)
• bundle install
• Run your tests/specs or rails s.
• Ask questions!
Web App Deployment
• A Rails app is no good without a solid
  deployment environment
• MRI deployment strategies leverage MRI
  strengths
• Need JVM deployment options to leverage
  JVM strengths
Web App Deployment
• MRI: HTTP server -> Ruby process(es)
 • Mongrel / Unicorn
 • Passenger
• JRuby: HTTP server -> JRuby threads
 • Rails app: config.threadsafe!
 • Be mindful of the threadsafety of your
    dependencies
Web App Deployment
• Deploying in Java Application Server
• Most self-contained option: WARbler!
 • JRuby web app -> deployable WAR
• Other options
 • Trinidad / Glassfish Gem
 • Torquebox
Lab 6: Deploy it
• We’ve ported an app to JRuby. Now
  deploy it!
 • $ gem install warbler
 • $ warble config
 • Browse/edit config/warble.rb
 • $ warble war # builds WAR
 • $ cp app.war [tomcat-home]/webapps
Questions?

• https://github.com/ajuckel/intro-to-jruby
• @ajuckel
• ajuckel@gmail.com

Contenu connexe

Tendances

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and youKai Koenig
 
RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling RedisRedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling RedisRedis Labs
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machineelliando dias
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friendKai Koenig
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Ryan Cuprak
 
JRuby and Google App Engine
JRuby and Google App EngineJRuby and Google App Engine
JRuby and Google App Enginejoshsmoore
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVMStaffan Larsen
 
JRuby - The Perfect Alternative
JRuby - The Perfect AlternativeJRuby - The Perfect Alternative
JRuby - The Perfect AlternativeRam Vijapurapu
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platformRuslan Shevchenko
 
Apache Camel K - Fredericia
Apache Camel K - FredericiaApache Camel K - Fredericia
Apache Camel K - FredericiaClaus Ibsen
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Tomer Gabel
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystemGeison Goes
 
Ruby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterRuby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterSteven Chau
 

Tendances (19)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling RedisRedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
 
Ruby On Rails Ecosystem
Ruby On Rails EcosystemRuby On Rails Ecosystem
Ruby On Rails Ecosystem
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
JRuby and Google App Engine
JRuby and Google App EngineJRuby and Google App Engine
JRuby and Google App Engine
 
Scalatra 2.2
Scalatra 2.2Scalatra 2.2
Scalatra 2.2
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVM
 
Scaling the Rails
Scaling the RailsScaling the Rails
Scaling the Rails
 
JRuby - The Perfect Alternative
JRuby - The Perfect AlternativeJRuby - The Perfect Alternative
JRuby - The Perfect Alternative
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
 
Apache Camel K - Fredericia
Apache Camel K - FredericiaApache Camel K - Fredericia
Apache Camel K - Fredericia
 
IDLs
IDLsIDLs
IDLs
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystem
 
Ruby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterRuby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles Nutter
 

En vedette

Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Charles Nutter
 
Michael Gilmour: 50% ROI Per Year on Domain Name Parking
Michael Gilmour: 50% ROI Per Year on Domain Name ParkingMichael Gilmour: 50% ROI Per Year on Domain Name Parking
Michael Gilmour: 50% ROI Per Year on Domain Name Parkingdomainsherpa
 
worksheets for oblique innovation models
worksheets for oblique innovation modelsworksheets for oblique innovation models
worksheets for oblique innovation modelsa-small-lab
 
Younicos-Image-Brochure-
Younicos-Image-Brochure-Younicos-Image-Brochure-
Younicos-Image-Brochure-Neil Durno
 
Marketing Agenzie di Viaggio
Marketing Agenzie di ViaggioMarketing Agenzie di Viaggio
Marketing Agenzie di ViaggioT SOLUTIONS
 
Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...Lasse Chor
 
Human(e) aspects of Tokyo
Human(e) aspects of TokyoHuman(e) aspects of Tokyo
Human(e) aspects of Tokyoa-small-lab
 
Photoshop designs presentation
Photoshop designs presentationPhotoshop designs presentation
Photoshop designs presentationJames Green
 
American government aspca
American government aspcaAmerican government aspca
American government aspcalmylmy1205
 

En vedette (20)

Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014
 
Music insitutions
Music insitutionsMusic insitutions
Music insitutions
 
Inglês
 Inglês Inglês
Inglês
 
Michael Gilmour: 50% ROI Per Year on Domain Name Parking
Michael Gilmour: 50% ROI Per Year on Domain Name ParkingMichael Gilmour: 50% ROI Per Year on Domain Name Parking
Michael Gilmour: 50% ROI Per Year on Domain Name Parking
 
Do you feel secure online? Beliefs and Attitudes on Security and Privacy
Do you feel secure online? Beliefs and Attitudes on Security and PrivacyDo you feel secure online? Beliefs and Attitudes on Security and Privacy
Do you feel secure online? Beliefs and Attitudes on Security and Privacy
 
worksheets for oblique innovation models
worksheets for oblique innovation modelsworksheets for oblique innovation models
worksheets for oblique innovation models
 
Younicos-Image-Brochure-
Younicos-Image-Brochure-Younicos-Image-Brochure-
Younicos-Image-Brochure-
 
Marketing Agenzie di Viaggio
Marketing Agenzie di ViaggioMarketing Agenzie di Viaggio
Marketing Agenzie di Viaggio
 
Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...
 
Human(e) aspects of Tokyo
Human(e) aspects of TokyoHuman(e) aspects of Tokyo
Human(e) aspects of Tokyo
 
อนุ แซ่โค้ว 51040968 แก้ไข
อนุ แซ่โค้ว 51040968 แก้ไขอนุ แซ่โค้ว 51040968 แก้ไข
อนุ แซ่โค้ว 51040968 แก้ไข
 
Next Internet Users: Perspectives on the UK and Poland
Next Internet Users: Perspectives on the UK and PolandNext Internet Users: Perspectives on the UK and Poland
Next Internet Users: Perspectives on the UK and Poland
 
Toolboxes wiifm2 optimised
Toolboxes wiifm2 optimisedToolboxes wiifm2 optimised
Toolboxes wiifm2 optimised
 
Oess NCRM Festival
Oess NCRM FestivalOess NCRM Festival
Oess NCRM Festival
 
Photoshop designs presentation
Photoshop designs presentationPhotoshop designs presentation
Photoshop designs presentation
 
P19 netinvet bcn_2013-1
P19 netinvet bcn_2013-1P19 netinvet bcn_2013-1
P19 netinvet bcn_2013-1
 
American government aspca
American government aspcaAmerican government aspca
American government aspca
 
Sustainability
SustainabilitySustainability
Sustainability
 
Sql waits
Sql waitsSql waits
Sql waits
 
Cells[1]
Cells[1]Cells[1]
Cells[1]
 

Similaire à Introduction to JRuby

Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby.toster
 
JRuby - The Best of Java and Ruby
JRuby - The Best of Java and RubyJRuby - The Best of Java and Ruby
JRuby - The Best of Java and RubyEvgeny Rahman
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaKeith Bennett
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018Charles Nutter
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012Charles Nutter
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9Gal Marder
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesAlexandra Masterson
 
Seattlerb why jruby
Seattlerb why jrubySeattlerb why jruby
Seattlerb why jrubysnacktime
 
Aloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyAloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyCharles Nutter
 

Similaire à Introduction to JRuby (20)

Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 
Euruko 2012 - JRuby
Euruko 2012 - JRubyEuruko 2012 - JRuby
Euruko 2012 - JRuby
 
JRuby - The Best of Java and Ruby
JRuby - The Best of Java and RubyJRuby - The Best of Java and Ruby
JRuby - The Best of Java and Ruby
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
 
GraalVM
GraalVMGraalVM
GraalVM
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
JRuby Basics
JRuby BasicsJRuby Basics
JRuby Basics
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
 
Seattlerb why jruby
Seattlerb why jrubySeattlerb why jruby
Seattlerb why jruby
 
Aloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyAloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRuby
 

Dernier

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Dernier (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Introduction to JRuby

  • 1. Introduction to JRuby Anthony Juckel ajuckel@gmail.com @ajuckel
  • 2. What is Ruby? • Dynamic/duck-typed language • Strongly object oriented • Open class definitions • Closures, blocks, and generators, oh my!
  • 4. What is JRuby? • JRuby == Ruby
  • 5. What is JRuby? • JRuby == Ruby • JRuby != Ruby
  • 6. What is JRuby? • JRuby == Ruby • JRuby != Ruby • JRuby == Ruby++
  • 7. How to install it? • Download from jruby.org • Install via rvm (but not on this wifi)
  • 8. What can I do with it? • Run Ruby code (1.8 or 1.9) • Access Java libraries from Ruby • Embed Ruby within a Java application
  • 9. Lab 1: Install it! • $ jruby -e ‘puts “Hello, World!”’ • $ jruby hello.rb • $ jruby --1.9 hello.rb • $ jirb • $ jruby --1.9 -S irb • $ JRUBY_OPTS=”--1.9” jirb
  • 10. RubyGems • Gems are units of software reuse in the Ruby world • Most Gems will work the same in JRuby as in MRI • Gems with native code _may_ work, but seek alternatives
  • 11. RubyGems • Gems can install library files • $ gem install json • require ‘json’ • Gems can install scripts • $ gem install rspec • $ jruby --1.9 -S rspec
  • 12. RubyGems • Some gems are only of interest on JRuby • jruby-openssl • activerecord-jdbc-adapter
  • 13. RubyGems • Others have JRuby-specific versions • nokogiri • Uses libxml on MRI • Uses Java XML libraries on JRuby
  • 14. Lab 2: Gems • $ gem search -r [gem] • jruby-openssl • $ gem install [gem] • rspec • $ gem list • json • $ gem rdoc • bundler • $ gem server • $ cd lab02 • $ rspec
  • 15. Launch Time • Yes, it can be a problem • MRI: Quick to start, speed remains constant • JVM: Slow to start, faster as hotspots are optimized
  • 16. Launch Time • What to do about it? • Tweak startup options to make JVM startup as fast as possible
  • 17. Launch Time • JVM Options (prefixed with -J with jruby) • -client (-J-client) • -XX:+TieredCompilation • -Xshare:dump / -Xshare:on
  • 18. Launch Time • JRuby Options • -X-C (turn off compilation) • --ng-server / --ng • --ng will get faster after several executions while the JVM optimizes
  • 19. Launch Time ITERATIONS=1000 rspec 1000 1.9.3 JRuby 100 JRuby -X-C JRuby NailGun 10 1 0.1 1000 100000 10000000
  • 20. Lab 3: Try it out • -J-client • -J-XX:+TieredCompilation • -J-Xshare:on • -X-C (turn off compilation) • --ng-server / --ng
  • 21. Launch Time (cont.) • Can be improved, but for small tasks cannot (yet?) match MRI • What options are left? • Guard • Spork
  • 22. Launch Time (cont.) • Iterate using MRI • Quickly verify small changes • Integrate using JRuby • Less frequent • May have longer test suites, perhaps more work, can afford to pay the start up cost
  • 23. ActiveRecord • An Object-Relational Mapping (ORM) library • Developed as part of Rails • Maps database data to Ruby classes
  • 24. ActiveRecord • activerecord: Core functionality • activerecord-*-adapter: Database-specific adapter layer
  • 25. ActiveRecord • MRI’s activerecord-*-adapters use native database libraries. • JRuby can use JDBC drivers • Must have JDBC adapter on classpath • activerecord-jdbc*-adapters
  • 26. Lab 4: ActiveRecord • $ gem install activerecord-jdbc-adapter • $ gem install activerecord-jdbcpostgresql-adapter • $ gem install activerecord-jdbcsqlite3-adapter • $ gem install activerecord-derby-adapter
  • 27. Converting Rails App • Rails itself (aside from ActiveRecord) is very compatible with JRuby • Gems used in any given project may or may not be. • jruby-lint can help identify potential issues.
  • 28. Converting Rails App • What are some known issues? • Some ObjectSpace methods disabled by default • Native code use • Kernel#fork / backtick operator / system usage
  • 29. Lab 5: Convert an App • $ cd graphy # Rails app targeting MRI 1.9.3 • If you’ve got MRI installed, look at current app • bundle install • rake db:create db:migrate db:seed • rails s
  • 30. Lab 5: Convert an App • $ jrlint • Update Gemfile • :platforms => :jruby • activerecord-jdbc*-adapter • :platforms => :ruby • pg, sqlite3
  • 31. Lab 5: Convert an App • After performing the updates, test the app in JRuby • Also test the app in MRI, if available • Having dependencies properly scoped should allow you to execute the app in either environment
  • 32. Lab 5: Convert an App • Have an app along with you? Try converting it now! • Install/Run jrlint • Update Gemfile (if necessary) • bundle install • Run your tests/specs or rails s. • Ask questions!
  • 33. Web App Deployment • A Rails app is no good without a solid deployment environment • MRI deployment strategies leverage MRI strengths • Need JVM deployment options to leverage JVM strengths
  • 34. Web App Deployment • MRI: HTTP server -> Ruby process(es) • Mongrel / Unicorn • Passenger • JRuby: HTTP server -> JRuby threads • Rails app: config.threadsafe! • Be mindful of the threadsafety of your dependencies
  • 35. Web App Deployment • Deploying in Java Application Server • Most self-contained option: WARbler! • JRuby web app -> deployable WAR • Other options • Trinidad / Glassfish Gem • Torquebox
  • 36. Lab 6: Deploy it • We’ve ported an app to JRuby. Now deploy it! • $ gem install warbler • $ warble config • Browse/edit config/warble.rb • $ warble war # builds WAR • $ cp app.war [tomcat-home]/webapps

Notes de l'éditeur

  1. Target audience(s!): Ruby developers new to the JVM; Java developers new to the Ruby Language\nRuby folks, the material in the first few labs may be quite familiar, but we’ll likely be moving quickly.\nJava folks, we’re going to gloss over language features\n
  2. You can’t really talk about what JRuby is without first defining Ruby\nThis is not a primer on Ruby as a language. More a whirlwind tour of the JRuby ecosystem.\n
  3. JRuby is ruby syntax and semantics through and through. Deviations are bugs.\nJVM as a platform has different sweetspots than the MRI VM as a platform\nFor a given set of tasks (CPU-bound performance, high concurrency needs, esoteric platforms) JRuby is a better\n
  4. JRuby is ruby syntax and semantics through and through. Deviations are bugs.\nJVM as a platform has different sweetspots than the MRI VM as a platform\nFor a given set of tasks (CPU-bound performance, high concurrency needs, esoteric platforms) JRuby is a better\n
  5. JRuby is ruby syntax and semantics through and through. Deviations are bugs.\nJVM as a platform has different sweetspots than the MRI VM as a platform\nFor a given set of tasks (CPU-bound performance, high concurrency needs, esoteric platforms) JRuby is a better\n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. View the source, run the tests, perhaps play with the code.\n\nOnce everyone’s comfortable running the tests, it’s time to move on.\n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. SCOPING dependencies to platform\n
  30. \n
  31. \n
  32. \n
  33. \n
  34. Tuesday at 2:00, Joe Kutner will be talking further about deployment\n
  35. \n
  36. \n