SlideShare ist ein Scribd-Unternehmen logo
1 von 83
Downloaden Sie, um offline zu lesen
JRuby in the Enterprise
About Me
Advisory Engineer at Constant Contact

Spent several years working for Sun/Javasoft in
the distributed computing group

Email: jerry@gulla.com

Twitter: @jerrygulla

Github: github.com/jgulla
What is JRuby?


Just a Ruby interpreter running on the JVM

Ruby 1.8.7 & 1.9.2 compatible.
Text-To-Join

Distributed app

Written in Ruby as a Rails app

Four rails apps, actually

UI, API, Console, SMS Processor.
JRUBY.ORG
Why Ruby?


Ruby is…A dynamic, open source programming
language with a focus on simplicity and
productivity. It has an elegant syntax that is natural
to read and easy to write.
WHY SHOULD YOU SWITCH TO RUBY? IF YOU ARE HAPPY WITH
 PERL OR PYTHON, YOU DON'T HAVE TO. BUT IF YOU DO FEEL
 THERE MUST BE A BETTER LANGUAGE, RUBY MAY BE YOUR
   LANGUAGE OF CHOICE. LEARNING A NEW LANGUAGE IS
  HARMLESS. IT GIVES YOU NEW IDEAS AND INSIGHTS. YOU
 DON'T HAVE TO SWITCH, JUST LEARN AND TRY IT. YOU MAY
   FIND YOURSELF COMFORTABLE ENOUGH WITH RUBY TO
                DECIDE TO SWITCH TO IT.

           -- YUKIHIRO MATSUMOTO (“MATZ”)
 HTTP://LINUXDEVCENTER.COM/PUB/A/LINUX/2001/11/29/
                      RUBY.HTML
Rails 3.x

“Optimized for programmer happiness”.
Why Not Grails?

Grails is great

Not as big of a break with Java

Wanted a bigger shift to bring new ways of doing
things into perspective.
Why JRuby?
High performance

  JVM Highly Tuned

Real threading

  Many “pure Ruby” shops using JRuby just for
  this

Vast array of libraries

  No need to abandon Java libraries.
Why JRuby Continued

Deployment Options

  Can deploy as a WAR file

Monitoring Options

  JVM tools to monitor all available

Speed of Development.
Don’t Freak the Ops
     Guys Out
  HTTP://UPLOAD.WIKIMEDIA.ORG/WIKIPEDIA/EN/F/F4/THE_SCREAM.JPG
http://commons.wikimedia.org/wiki/File:Everest-fromKalarPatar.jpg




          Scalability
Concurrency is a Myth




 HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
ILYA GRIGORIK
                HTTP://WWW.IGVITA.COM/ABOUT/




 JRUBY IS, IN FACT, THE ONLY RUBY IMPLEMENTATION
THAT WILL ALLOW YOU TO NATIVELY SCALE YOUR RUBY
 CODE ACROSS MULTIPLE CORES. BY COMPILING RUBY
 TO BYTECODE AND EXECUTING IT ON THE JVM, RUBY
THREADS ARE MAPPED TO OS THREADS WITHOUT A GIL
IN BETWEEN - THAT'S AT LEAST ONE REASON TO LOOK
                     INTO JRUBY.
   HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
“Enterprise” JRuby
“Enterprise” JRuby Cont.
Maven

Liquibase

JDBC

JNDI

Containers

You’re favorite commercial, open-source or home-
grown library.
Let’s Begin
          http://commons.wikimedia.org/wiki/File:Begin_road.JPG
http://commons.wikimedia.org/wiki/File:Panama_Canal_Locks_Construct.jpeg




    Set up Ruby
Ruby Version Manager




    HTTPS://RVM.BEGINRESCUEEND.COM/
Installing RVM


Via git repo (preferred method)
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Other methods at https://rvm.beginrescueend.com/rvm/install/
Install JRuby (via rvm)
rvm install jruby-1.6.3

When it’s done, use it:

  rvm use jruby-1.6.3

List of other ruby versions to install:

  rvm list known

List versions of ruby you have installed:

  rvm list
JRuby Without RVM


Assume Java, JRuby in your path

jruby -S gem ...
Install Rails


gem install rails

Can pick a specific version with a
“-v” flag.
Create Your Rails App
Jruby.org hosts a rails template

  Sets things up to run under native ruby or JRuby

  You can do this yourself, but it’s handier to start this
  way

rails new uberconf_demo --template=http://jruby.org

  Works with native ruby or JRuby.
Jruby.org Template
Demo
Packaging Your App




   http://en.wikipedia.org/wiki/File:Distribution_differences.jpg
JRuby/Rails/WAR files
In the Java world, WAR files are standard

Fortunately, we have bundler

  Gem to package your Rails app as a WAR file

Can even make it “Executable” for stand-alone
testing!

http://caldersphere.rubyforge.org/warbler/
Install it


Easy!

gem install warbler
Run It




             http://en.wikipedia.org/wiki/File:Jeanette_Kwakye_cropped.jpg

Easy!

warble war
Other Useful Options
warble compiled    # Feature: precompile all Ruby files

warble config      # Generate a configuration file to customize your archive

warble executable # Feature: make an executable archive

warble gemjar     # Feature: package gem repository inside a war

warble pluginize # Install Warbler tasks in your Rails application

warble version    # Display version of Warbler

warble war       # Create the project war file

warble war:clean # Remove the project war file

warble war:debug # Dump diagnostic information
Maven

In the Java world, Maven is still pretty popular

  For better or for worse

You can use Maven to invoke warbler to package
your app.
Database Migrations




http://en.wikipedia.org/wiki/File:Connochaetes_taurinus_-Wildebeest_crossing_river_-East_Africa.jpg
Database Migrations
Rails uses Rake for ActiveRecord migrations

Nice, but

  Hard to scale to multiple developers

  Hard to deploy to QA/Production systems
  without using ruby toolset

  Paranoid DBAs can’t see the SQL before
  running it.
Enter

liquibase.org

Version control for your database

Other frameworks (Grails) will be adopting it for
migrations

Language/Database agnostic.
Liquibase

Nothing special about using Liquibase with Rails

Use ActiveRecord migrations for initial dev/testing,
then migrate to Liquibase

When ready, just take “snapshot” of DB config,
then roll out new Liquibase changesets.
Handy Liquibase Commands
Generate initial changelog:
java -jar liquibase.jar --classpath=mysql-connector-
java-5.1.14-bin.jar --url=jdbc:mysql://localhost/
api_development --driver=com.mysql.jdbc.Driver --
username=demo --password=password --
changeLogFile=db-changelog.xml generateChangeLog

Drop all tables so you can start over:
dropAll

Run updates against a DB:
liquibase --changeLogFile=myChangeLog update

Just output SQL, don’t run: updateSQL
USING
 LIQUIBASE
WITH MAVEN
Liquibase with Rails Directly


https://github.com/redbeard/liquibase-rails

Supposed to add “drop in” migration tasks for
JRuby/Rails.
Liquibase Changeset
JNDI Database Access
       DATABASE.YML
Servlet Filters



You’ll need a custom web.xml config

Copy WARBLER_HOME/web.xml.erb to
  config/web.xml.erb

  Look for it at ~/.rvm/gems/jruby-1.6.2/gems/
  warbler-1.3.1/web.xml.erb
     HTTP://EN.WIKIPEDIA.ORG/WIKI/FILE:DICHROIC_FILTERS.JPG
web.xml.erb Filter Entry
Java Integration

Nothing special, just the usual JRuby/Java
integration

Looks for JARs in the container classpath, WAR or
in yourapp/lib
Calling Java




HTTPS://GITHUB.COM/JRUBY/JRUBY/WIKI/CALLINGJAVAFROMJRUBY
Tips, Tricks and Lessons




 http://en.wikipedia.org/wiki/File:Coolidge_after_signing_indian_treaty.jpg
Warbler Config


generate a warbler config file

warble config
Pre-Compile Ruby Classes



config.features = %w(compiled)
Set Min/Max Runtimes
Set JNDI Source Name
Set Root Path for App


By default, the root of your app is the WAR name

This may not be what you want.
Set the Root Path
Create file jboss-web.xml in root of app directory




Tell warbler to include it via warble.rb
Bundle Up Files into A
Gem
Can be much faster to build/deploy depending on
how you do it (there are a lot of files!)

Make sure to test it
Make Your War Executable


Command Line:
warble executable war

 In warble.rb:
 config.features = %w(executable)
Rails Console


Rails has a “Console Mode” for testing

Great for trying out ActiveRecord queries, etc.

Just use “rails console” to invoke it.
Gem Versions

Be sure to lock down Gem versions when you’re
happy with them

Don’t want any last minute “upgrades!”

Use bundler

Put Gemfile.lock under source control.
Basic Versioning Rules
After bundling, always check your Gemfile.lock
into version control

After updating your Gemfile, always run
bundle install first.

When running an executable, ALWAYS use
bundle exec [command]

   The only exception is the rails command!
http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/
Handle Database Connection Outage




This is the “default” 500 error page.
You can Customize this
but...


You can do better
Create “Status” URL


Want a well known URL that Nagios or a Load
Balancer can check

Should return something useful (and specific to
your test).
Insert Your Own Middleware
Create lib/db_check.rb
Insert Your Own Middleware
Insert it into the stack (application.rb)
You Now Have Generic Status Ability




Extend for other things useful to your application.
HTTP://TORQUEBOX.ORG/
IDEs
Resources
Books
Websites

http://www.jruby.org/

http://jrubyconf.com/

http://vimeo.com/groups/87639
(talks from 2010 JRubyConf)

http://www.engineyard.com/open-source
Twitter Users


http://twitter.com/#!/headius

http://twitter.com/#!/nicksieger

http://twitter.com/#!/jruby
Questions?
Thank You!
Don’t forget to fill out a session evaluation!

Weitere ähnliche Inhalte

Was ist angesagt?

Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
elliando dias
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
elliando dias
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
deimos
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
OpenBlend society
 

Was ist angesagt? (20)

Ruby On Rails Ecosystem
Ruby On Rails EcosystemRuby On Rails Ecosystem
Ruby On Rails Ecosystem
 
Ruby for devops
Ruby for devopsRuby for devops
Ruby for devops
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
 
Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009
 
Cloud Foundry 百日行 振り返り
Cloud Foundry 百日行 振り返りCloud Foundry 百日行 振り返り
Cloud Foundry 百日行 振り返り
 
GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
Java10 and Java11 at JJUG CCC 2018 Spr
Java10 and Java11 at JJUG CCC 2018 SprJava10 and Java11 at JJUG CCC 2018 Spr
Java10 and Java11 at JJUG CCC 2018 Spr
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18
 
Rails On Spring
Rails On SpringRails On Spring
Rails On Spring
 
The bigrabbit
The bigrabbitThe bigrabbit
The bigrabbit
 
Introduction to JRubMe
Introduction to JRubMeIntroduction to JRubMe
Introduction to JRubMe
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystem
 
Inside the JVM
Inside the JVMInside the JVM
Inside the JVM
 
Why we use mruby with Perl5?
Why we use mruby with Perl5?Why we use mruby with Perl5?
Why we use mruby with Perl5?
 
Aspect Orientated Programming in Ruby
Aspect Orientated Programming in RubyAspect Orientated Programming in Ruby
Aspect Orientated Programming in Ruby
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 

Ähnlich wie JRuby in the enterprise

Instruments ruby on rails
Instruments ruby on railsInstruments ruby on rails
Instruments ruby on rails
pmashchak
 
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
 
JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
elliando dias
 
Ruby and Rails short motivation
Ruby and Rails short motivationRuby and Rails short motivation
Ruby and Rails short motivation
jistr
 

Ähnlich wie JRuby in the enterprise (20)

JRuby in a Java World
JRuby in a Java WorldJRuby in a Java World
JRuby in a Java World
 
JRuby deployments
JRuby deploymentsJRuby deployments
JRuby deployments
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
Instruments ruby on rails
Instruments ruby on railsInstruments ruby on rails
Instruments ruby on rails
 
JRuby Basics
JRuby BasicsJRuby Basics
JRuby Basics
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Jaoo Michael Neale 09
Jaoo Michael Neale 09Jaoo Michael Neale 09
Jaoo Michael Neale 09
 
First Day With J Ruby
First Day With J RubyFirst Day With J Ruby
First Day With J Ruby
 
Crank Up Your Apps With TorqueBox
Crank Up Your Apps With TorqueBoxCrank Up Your Apps With TorqueBox
Crank Up Your Apps With TorqueBox
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
 
Introduction To Rails
Introduction To RailsIntroduction To Rails
Introduction To Rails
 
Ruby On Google App Engine 2nd Athens Ruby Me
Ruby On Google App Engine 2nd Athens Ruby MeRuby On Google App Engine 2nd Athens Ruby Me
Ruby On Google App Engine 2nd Athens Ruby Me
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
 
Ruby and Rails short motivation
Ruby and Rails short motivationRuby and Rails short motivation
Ruby and Rails short motivation
 
Scala on Rails #rakutentech
Scala on Rails #rakutentechScala on Rails #rakutentech
Scala on Rails #rakutentech
 
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

JRuby in the enterprise