SlideShare a Scribd company logo
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

More Related Content

What's hot

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 
2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo
Paul Heaberlin
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
Kai 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 Redis
Redis Labs
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
elliando dias
 
Ruby On Rails Ecosystem
Ruby On Rails EcosystemRuby On Rails Ecosystem
Ruby On Rails Ecosystem
Andrew Chalkley
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
Kai 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 Engine
joshsmoore
 
Scalatra 2.2
Scalatra 2.2Scalatra 2.2
Scalatra 2.2
Ivan Porto Carrero
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVM
Staffan Larsen
 
Scaling the Rails
Scaling the RailsScaling the Rails
Scaling the Rails
elliando dias
 
JRuby - The Perfect Alternative
JRuby - The Perfect AlternativeJRuby - The Perfect Alternative
JRuby - The Perfect Alternative
Ram Vijapurapu
 
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
 
Apache Camel K - Fredericia
Apache Camel K - FredericiaApache Camel K - Fredericia
Apache Camel K - Fredericia
Claus Ibsen
 
IDLs
IDLsIDLs
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 ecosystem
Geison 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 Nutter
Steven Chau
 

What's hot (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
 

Viewers also liked

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
Charles Nutter
 
Inglês
 Inglês Inglês
Inglês
xavelhinha
 
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
domainsherpa
 
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
Oxford Martin Centre, OII, and Computer Science at the University of Oxford
 
worksheets for oblique innovation models
worksheets for oblique innovation modelsworksheets for oblique innovation models
worksheets for oblique innovation models
a-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 Tokyo
a-small-lab
 
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
Oxford Martin Centre, OII, and Computer Science at the University of Oxford
 
Toolboxes wiifm2 optimised
Toolboxes wiifm2 optimisedToolboxes wiifm2 optimised
Toolboxes wiifm2 optimised
Queensland VET Development Centre
 
Oess NCRM Festival
Oess NCRM FestivalOess NCRM Festival
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
 
Sustainability
SustainabilitySustainability
Sustainability
Montgomery Norton
 
Sql waits
Sql waitsSql waits
Cells[1]
Cells[1]Cells[1]

Viewers also liked (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]
 

Similar to Introduction to JRuby

Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
.toster
 
Euruko 2012 - JRuby
Euruko 2012 - JRubyEuruko 2012 - JRuby
Euruko 2012 - JRuby
Charles Nutter
 
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
 
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
Charles Nutter
 
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
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
Charles Nutter
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
Marcin Gryszko
 
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 2012
Charles Nutter
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
Barry Jones
 
GraalVM
GraalVMGraalVM
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
JRuby Basics
JRuby BasicsJRuby Basics
JRuby Basics
elliando dias
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
Gal Marder
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
Kresten Krab Thorup
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
Seattlerb why jruby
Seattlerb why jrubySeattlerb why jruby
Seattlerb why jruby
snacktime
 
Aloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyAloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRuby
Charles Nutter
 

Similar to 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
 

Recently uploaded

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 

Recently uploaded (20)

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 

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

Editor's Notes

  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