Top Banner
Your First Day with JRuby on Rails Your First Day with JRuby on Rails Charles Nutter and Thomas Enebo Charles Nutter and Thomas Enebo Except where otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License (http://creativecommons.org/licenses/by-sa/3.0/us/).
102

Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

May 08, 2018

Download

Documents

nguyenkien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

Your First Day with JRuby on RailsYour First Day with JRuby on Rails

Charles Nutter and Thomas EneboCharles Nutter and Thomas Enebo

Except where otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution­Share Alike 3.0 United States License (http://creativecommons.org/licenses/by­sa/3.0/us/).

Page 2: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

2

Welcome!

What will we cover:JRuby 101 – Fluff 'n StuffJustification! (or: Dear god, why?)JRuby on Rails – The BasicsDeployment Options – How Easy Can They Be?Migration – Steps, Gotchas, and PitfallsBeyond Rails – Creating Your Own Chimera

Page 3: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

3

Your Humble Hosts

Charles Oliver Nutter and Thomas EneboLongtime Java developers (10+ yrs each)Shorttime engineers at Sun MicrosystemsFull-time JRuby developersAlso working to build out JVM dynlang supportWide range of past experience

C, C++, C#, Perl, Python, Delphi, Lisp, SchemeJava EE and ME, JINI, WS

Page 4: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

4

Off We Go!

JRuby 101

Page 5: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

5

A Floor Wax and a Dessert Topping

JRuby is:Ruby (1.8ish)A non-Java language for the Java platformA new way to look at Ruby and the JVMHelping to expand Ruby's reachHelping the world better understand RubyReally cool

Page 6: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

6

A Floor Wax and a Dessert Topping

JRuby is not:An attempt to pollute or fork RubyAn admission that Java sucksThe answer to every problem with RubyAn attempt to alter Ruby or add incompatible featuresSlow

Page 7: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

7

It Really Is Ruby

ruby 1.8.5 (2007-04-29 rev 3539) [i386-jruby0.9.9]

Page 8: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

8

Based on Ruby 1.8.x

ruby 1.8.5 (2007-04-29 rev 3539) [i386-jruby0.9.9]

Page 9: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

9

Just Another Implementation

ruby 1.8.5 (2007-04-29 rev 3539) [i386-jruby0.9.9]

Page 10: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

10

But It's Java, Too

include Javaimport java.lang.ArrayListimport javax.swing.JFrame

list = ArrayList.newframe = JFrame.new(“Ruby SWINGS!”)list << framelist.each {|f| f.set_size(200,200) }

Page 11: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

11

Java When You Want It

include Javaimport java.lang.ArrayListimport javax.swing.JFrame

list = ArrayList.newframe = JFrame.new(“Ruby SWINGS!”)list << framelist.each {|f| f.set_size(200,200) }

Page 12: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

12

Libraries You Need

include Javaimport java.lang.ArrayListimport javax.swing.JFrame

list = ArrayList.newframe = JFrame.new(“Ruby SWINGS!”)list << framelist.each {|f| f.set_size(200,200) }

Page 13: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

13

But Rubified!

include Javaimport java.lang.ArrayListimport javax.swing.JFrame

list = ArrayList.newframe = JFrame.new(“Ruby SWINGS!”)list << framelist.each {|f| f.set_size(200,200) }

Page 14: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

14

Getting JRuby

Download from JRuby.org

Page 15: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

15

Demo

Setting Up JRuby

Page 16: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

16

Getting JRuby

Build it yourself

Page 17: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

17

The Rest Is Stuff You Know

RubyGems 0.9.1 is preinstalledgem install rails -y --no-ri --no-rdocgem install ActiveRecord-JDBC

Mongrel supports JRubyNo remote gem, download from jruby-extras project

Rails “just works”Lots of effort put into making Rails run wellMajor orgs now investing in JRuby on Rails

Page 18: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

18

What Hath Man Wrought?

Justificationor

Dear god, why would you do such a thing?

Page 19: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

19

Is Ruby Perfect?

Granted, we all love Ruby.Except unicode support.And threading.Scaling Rails could be easier.I don't want to write it in C to get performance.

Ruby 2.0 promises solutions...but what about today?

Page 20: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

20

Unicode Support

Supporting the Status QuoJRuby support's Ruby 1.8's StringJRuby works with ActiveSupport::MultiByte

Exposing Java UnicodeJava strings are all unicodeJava libraries are all unicode-friendlyRuby and Java strings go back and forth safely

Ruby 2.0 String support on the way...

Page 21: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

21

Threading

JRuby supports Ruby's Thread APIEven the ones we hate: critical=, kill, raise

But most JVMs are native-threadedOne JRuby thread = one system threadUse multiple cores, spin off long-running jobs

JRuby also supports thread poolingKeep threads warm for quick hitsTypically-sited use for green threads

Page 22: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

22

Threading

True Concurrent Threading

Page 23: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

23

But threading and unicodeare implementation details.

Page 24: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

24

What is the biggest reason for JRuby?

Page 25: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

25

Now It Gets Interesting

JRuby on Rails: The Basics

Page 26: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

26

Differentiation

Lots of things are the same.

Page 27: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

27

Differentiation

Many (most?) gems just work.

Rails (of course)RedCloth, BlueCloth

Hpricot

Basically, anything pure Ruby (or with a JRuby port).

Page 28: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

28

Differentiation

Typical Rails commands just work.

rails myappjruby script/generate controller test hello

rake db:migrate

Command-line dev looks basically the same.

Page 29: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

29

Differentiation

Basic server use is the same.

jruby script/server => WEBrickgem install mongrel-1.0.1-jruby.gem

jruby script/server => Mongrel

So development-time serving works about the same.

Page 30: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

30

Demo

Creating the App and Running the server

Page 31: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

31

Differentiation

In general, it's just Ruby on Rails!

Page 32: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

32

Differentiation

But a few things are different.

(otherwise what would be the point?)

Page 33: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

33

Differentiation

Big Difference #1: Database Support

Page 34: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

34

database.yml

Default pure-Ruby MySQL driver works...

development: adapter: mysql database: testapp_development username: testapp password: testapp host: localhost

Page 35: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

35

database.yml

Different and faster, but just as easy.

development: adapter: jdbc url: jdbc:mysql://localhost/testapp_dev username: testapp password: testapp driver: com.mysql.jdbc.Driver

Page 36: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

36

database.yml

JNDI for connection pooling

development: adapter: jdbc jndi: java:comp/env/jdbc/MyAppPool driver: mysql

Page 37: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

37

environment.rb

Make sure to require the “jdbc” adapter

...require 'jdbc_adapter'

Rails::Initializer.run do |config|...

Page 38: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

38

CLASSPATH Returns!

You thought you'd seen the last of it...

export CLASSPATH=mysql-driver.jar

But there's an easier way.

cp mysql-driver.jar ~/work/jruby/lib

Page 39: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

39

Demo

Configuring the database

Page 40: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

40

Almost Every Database Supports JDBC

4th Dimension (4D RDBMS), ADABAS, ALLBASE SQL, Advantage Database Server, Advantage Ingres 2.6, Apache Derby, BASIS, Birdstep RDM Server, CA-IDMS, CISAM,

Cache, Centura SQLBase, Clipper, Cloudscape, CodeBase, D3, DABroker, DB2, DB2 IBM AS/400 UNIX, DB2 Linux, DB2 OS/390, DB2 Windows, DBMaker, DL/I, DMSII, DaffodilDB, DataFlex/PowerFlex, Datacom, Domino, ECB, EDA, Empress RDBMS, Enscribe, Essentia,

FireBirdSQL , FirstSQL/J Embedded Mobile, FirstSQL/J Enterprise Server, FormWeb, FoxBase, FoxPro, FrontBase, H2 Database, HSQLDB, IBM AS/400, IDMS, IMS,

Image/Turboimage, ImageSQL, Informix, Ingres, InstantDB, InterBase, JDataStore, Java DB, LDAP, MS Access, MS SQL Server, Mimer SQL, MySQL, News Server, Nonstop SQL/MP, ODBC, OS/390 Sequential Files, OleDB-Provider, OpenBase, OpenIngres,

Oracle, PICK, Paradox, Pervasive.SQL, PointBase, PostgreSQL, Primebase SQL Database Server, Progress, Quadcap, RDB, RMS, Recital, Redbrick Warehouse, SAP DB, SAS,

SESAM/SQL-Server, SOLID Embedded Engine, SOLID SynchroNet, SQL/DS, SQLLite, SUPRA Server SQL, SearchServer, Sequential, Solid Server, Sybase, Teradata RDBMS, Text (CSV, Tab separated etc.), ThinkSQL, TinySQL, TurboIMAGE, UNIFY, VFP, VSAM,

XML, YARD-SQL, dBase, kdb, mSQL, xbase, xbase

Page 41: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

41

Including Yours...

4th Dimension (4D RDBMS), ADABAS, ALLBASE SQL, Advantage Database Server, Advantage Ingres 2.6, Apache Derby, BASIS, Birdstep RDM Server, CA-IDMS, CISAM,

Cache, Centura SQLBase, Clipper, Cloudscape, CodeBase, D3, DABroker, DB2, DB2 IBM AS/400 UNIX, DB2 Linux, DB2 OS/390, DB2 Windows, DBMaker, DL/I, DMSII, DaffodilDB, DataFlex/PowerFlex, Datacom, Domino, ECB, EDA, Empress RDBMS, Enscribe, Essentia,

FireBirdSQL , FirstSQL/J Embedded Mobile, FirstSQL/J Enterprise Server, FormWeb, FoxBase, FoxPro, FrontBase, H2 Database, HSQLDB, IBM AS/400, IDMS, IMS,

Image/Turboimage, ImageSQL, Informix, Ingres, InstantDB, InterBase, JDataStore, Java DB, LDAP, MS Access, MS SQL Server, Mimer SQL, MySQL, News Server, Nonstop SQL/MP, ODBC, OS/390 Sequential Files, OleDB-Provider, OpenBase, OpenIngres,

Oracle, PICK, Paradox, Pervasive.SQL, PointBase, PostgreSQL, Primebase SQL Database Server, Progress, Quadcap, RDB, RMS, Recital, Redbrick Warehouse, SAP DB, SAS,

SESAM/SQL-Server, SOLID Embedded Engine, SOLID SynchroNet, SQL/DS, SQLLite, SUPRA Server SQL, SearchServer, Sequential, Solid Server, Sybase, Teradata RDBMS, Text (CSV, Tab separated etc.), ThinkSQL, TinySQL, TurboIMAGE, UNIFY, VFP, VSAM,

XML, YARD-SQL, dBase, kdb, mSQL, xbase, xbase

Page 42: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

42

Does JDBC Support Mean Rails Support?

ActiveRecord-JDBC doesn't support all of themJDBC has no schema management APIDifferent databases quote differentlySome databases are missing features

We focused on databases close to Rails, JRubyMySQL passes 100% of ActiveRecord tests (yay!)Derby 34F, PostgreSQL, 17F (out of 1000+ tests)Others at varying levels, but coming along

Page 43: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

43

Differentiation

Big Difference #2: No Native Extensions*

*At least, not until ports are available

Page 44: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

44

Native Extensions

Some ports done, some in progressMongrel: doneHpricot: doneDatabase support: some done, some in progressRMagick: in progress

We're looking for porters and recommendations

Page 45: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

45

Native Extensions

More and more extensions will support JRuby

...but for now pure-Ruby versions are best

Page 46: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

46

Differentiation

Big Difference #3: Command-line Performance

Page 47: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

47

Same Old Story

No, Java isn't slow.

Page 48: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

48

Same Old Story

...except at startup.

Page 49: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

49

JRuby on Java 6 Server VM

~/work/jruby $ jruby SERVER bench_fib_recursive.rb 2.071000 0.000000 2.071000 ( 2.070000) 1.234000 0.000000 1.234000 ( 1.234000) 1.372000 0.000000 1.372000 ( 1.373000) 1.372000 0.000000 1.372000 ( 1.372000)

~/work/jruby $ ruby -vruby 1.8.5 (2006-12-25 patchlevel 12) [i686-darwin8.8.1]~/work/jruby $ ruby bench_fib_recursive.rb 1.670000 0.010000 1.680000 ( 1.680365) 1.660000 0.010000 1.670000 ( 1.675206) ...

Page 50: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

50

Same Old Story

So don't expect stellar CLI performance.

Page 51: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

51

That's It?

Yup, that's about it.Other stuff should just work.

And now for something completely different...

Page 52: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

52

How Easy Can It Be?

Deployment

Page 53: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

53

The Old Way Works

Option #1: Just use Mongrel

Page 54: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

54

The Old Way Works

Mongrel is supported by JRubySome bits won't work

Forking off subprocessesProcess management

Some folks are running JRuby/MongrelMost typical Mongrel setups should work

(What, you don't know if they'll work?)

Page 55: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

55

The Old Way Works

Mongrel works great, no argument there.

Page 56: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

56

The Old Way Works

Capistrano makes it a lot easier.

Page 57: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

57

The Old Way Works

But haven't we solved this problem before?

Page 58: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

58

The New Way

Option #2: Deploy to an app server

Page 59: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

59

East Meets West

Introducing GoldSpike!Rails plugin for building WAR files

That's “Web application ARchive”

One plugin, pure Ruby (even works in MRI)Out comes a deployable WAR fileServer-agnostic

But GlassFish fairly rocks (glassfish.dev.java.net)

Page 60: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

60

Spike It!

~/work/jruby/testapp $ jruby script/plugin install \

svn://rubyforge.org/var/svn/jruby-extras/trunk/ \

goldspike/plugins/goldspike~/work/jruby/testapp $ rake war:standalone:create

(in /Users/headius/work/jruby/testapp)

Assembling web application

...

Adding Java library jruby-complete-0.9.9

...

Adding web application

Adding Ruby gem rails version 1.2.3

...

Creating web archive

~/work/jruby/testapp $ ls -l testapp.war

-rw-r--r-- 1 headius headius 6386396 Apr 30 18:47 testapp.war

Page 61: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

61

Customizing Your Webapp

config/war.rb:

add_gem 'tzinfo'maven_library 'mysql', 'mysql-connector-java', '5.0.5'

Page 62: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

62

Demo

Using GoldSpike with GlassFish

Page 63: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

63

Even Newer?

Option #3: A “Pack” in a Box?

Page 64: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

64

Bridging the Gap

It's well understoodthat Rails developers

may not like app servers.

Page 65: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

65

Bridging the Gap

Is there a middle ground?

Page 66: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

66

The Newest Way

~/work/jruby/testapp $ gem install glassfish-rails~/work/jruby/testapp $ jruby script/server glassfish=> Starting GlassFish=> Rails application at http://localhost:8080=> Admin services at http://localhost:4848=> Clustering enabled=> Connection pooling enabled=> Load balancing enabled=> Server Ready.

Page 67: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

67

Tease!

Not Yet.But Soon :)

Page 68: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

68

Making a Move

Migration

Page 69: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

69

Migration

It can be done!(it's basically just Ruby, after all)

Page 70: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

70

Migration

The areas of concern arethe (currently) unsupported features.

Page 71: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

71

Migration

Case Study: Mephisto

Mephisto is a kick ass web publishing system. It’s a blog engine with some simple CMS-ish concepts (sections, pages), a very flexible templating system, and an aggressive caching

scheme that takes advantage of your web server’s best traits.

Page 72: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

72

Migration

Step One: Database Support

Page 73: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

73

Migration

MySQL

Well-supportedNo known issues

ActiveRecord tests 100%Included in our continuous integration

Page 74: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

74

Migration

Derby (JavaDB) and HSQLDB

Working well (fewer failures every week)Embeddable and shippableGood target for small apps

Included in our continuous integration

Page 75: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

75

Migration

PostgreSQL

Down to a few failuresIncluded in our continuous integration

Page 76: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

76

Migration

Oracle

Being used by some in communityStarting to get our attention

May be in continuous integration now

Page 77: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

77

Migration

MS SQL, DB2, others

Used in communityHave not started to investigate

Not part of continuous integrationLooking for folks to help here

Page 78: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

78

Migration

Migrations

Working well, because they're part of Rails testsTricky on some DBs that don't have all features

Page 79: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

79

Migration

Fixtures

Also working well, part of Rails testsUsually bugs are YAML rather than DB issues

Page 80: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

80

Migration

Step Two: Native Extensions

You have a few options...

Page 81: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

81

Migration

Option #1Use something else

Page 82: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

82

Migration

Option #2Use an equivalent Java library

Page 83: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

83

Migration

Option #3Port the library yourself (sometimes pretty easy)

Page 84: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

84

Migration

Option #4 (our favorite!)Port by wrapping a Java library

(often even easier)

Page 85: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

85

Example Extensions

Hpricot – Ragel generator supports JavaMongrel – DittoRMagickJr – Wraps builtin Java graphics supportJParseTree – Pure Ruby, but uses JRuby ASTOpenSSL – Complete port of OpenSSL (really!)YAML – Complete implementation in Java

Page 86: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

86

Ship It!

Step Three: Choosing a Deployment Option

Page 87: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

87

Ship It!

Two real options, a third in development.

Page 88: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

88

Choosing a Deployment Option

You must balance features with convenience.

Page 89: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

89

Choosing a Deployment Option

And we want to help build a better way.

Page 90: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

90

Tried and True: Mongrel

MongrelYou know the good reasons, they still applySome community use, but little testingYou thought n Ruby processes took up memory!Not utilizing best of JRuby and JVM

Page 91: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

91

A Taste of the Old World

Web Archive in App ServerMulti-app, multi-request concurrencyMost servers support transparent clusteringResource pooling

Database connections, cached resultsExecution threadsRequest handlers

Access to the “good” Java EE features

Page 92: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

92

Whoa, What “Good” Java EE Features?

Java EE has a lot of bathwater, but a lot of babyJava Message ServiceJava Persistence API (good riddance Entity Beans)Java Transaction APIEasy deployment, clustering, failover, managementScales great

Though Java's complexity makes it tricky

Page 93: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

93

Coming Soon

A Grizzly/GlassFish v3 optionLightweight, gem-installable like MongrelConcurrency, pooling, multi-app like WARCompletes the deployment story for JRubyLooking for suggestions and help!

Page 94: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

94

Demo

Putting it all together with Mephisto

Page 95: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

95

The Transformed Man

Beyond Rails

Creating your own Chimera

Page 96: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

96

There's a Whole Platform Out There

Billions of lines of Java code out thereTens of thousands of deploymentsThousands of librariesThe Java platform is mature, trusted, reliable

...and often boring!

So why not combine two greats?Ruby as the programming languageJava for the platform and libraries

Page 97: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

97

Our Chimera

Best of all worldsRuby or Rails as the application layerJava libraries, alone or as ported gemsJava-based services...legacy integrationThe JVM

Acceptable to today's enterprise“Enterprise-ready” without losing the Ruby WayTo them: “it's just Java”, to you: “It's just Ruby”

Page 98: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

98

Demo

Calling Java from Rails

Page 99: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

99

Building a Better Toolset

You all have your tried and true toolsTextmate, Emacs, VI(M), plus command lineYou know them and you love them

But you're missing somethingCode completion?Jump to declaration?Rename variables?Pop-up RDoc?

Page 100: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

100

NetBeans Ruby Support

Best Ruby IDE availablecode completion in dozens of wayssmart syntax highlightingmore and more refactoringsjump to method, variable, class declarationspop-up RDocfull project support for Ruby or Rails appseverything else IDEs do: version control, etc

Page 101: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

101

Demo

NetBeans Ruby and Rails Support

Page 102: Your First Day with JRuby on Rails - s3.amazonaws.com Day with... · Migration – Steps, Gotchas, and Pitfalls Beyond Rails – Creating Your Own Chimera. 3 Your Humble Hosts Charles

102

A New Beginning

JRuby: www.jruby.orgJRuby Wiki: www.headius.com/jrubywikiNetBeans: www.netbeans.orgNetBeans Ruby: wiki.netbeans.org/wiki/view/RubyJRuby Extras: rubyforge.org/projects/jruby-extrasCharlie's Blog: headius.blogspot.comTom's Blog:

bloglines.com/blog/ThomasEEnebo