SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 
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
Redis Labs
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
elliando dias
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
Ruslan Shevchenko
 

Mais procurados (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
 

Destaque

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 Viaggio
T SOLUTIONS
 
Photoshop designs presentation
Photoshop designs presentationPhotoshop designs presentation
Photoshop designs presentation
James Green
 
American government aspca
American government aspcaAmerican government aspca
American government aspca
lmylmy1205
 

Destaque (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]
 

Semelhante a Introduction to 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
Evgeny Rahman
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
Keith Bennett
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian
 
Seattlerb why jruby
Seattlerb why jrubySeattlerb why jruby
Seattlerb why jruby
snacktime
 

Semelhante a 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
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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

Notas do Editor

  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