why jruby?
DESCRIPTION
When should you choose JRuby, a JVM-based implementation of Ruby, over MRI, the default C-based implementation? JRuby offers access to Java libraries, better performance, and can be deployed on Java-based infrastructure.TRANSCRIPT
Why JRuby?Fiona Tay @msfionatayEngineer, Pivotal Labs
This is for the person who just wants to make web apps.
This is about the Good, The Bad, and The Ugly.
I’m a Rubyist
4
I’m also a JRubyist
http://github.com/GreenplumChorus/chorus
5
An Introduction
It’s a Ruby implementation1. Install it2. Write Ruby code
7
It’s a Ruby implementation
8
Ruby implementationsInterchangeable to an extentPopular implementations:• MRI• JRuby• Rubinius • MacRuby
9
Under the hood
10
Under the hood
11
secret sauce
Interchangeability1+1 should be 2 in all implementations
12
Implementation differencesSome implementations are more equal than others Differences:• Speed of execution• Support for libraries• Implementation bugs
13
History of JRubyAround since 2002Has had traction in real projects since ~2005
14
JRuby in the real world
15
JRuby in the real world
16
The Good
Access to Java librariesIncredibly powerful toolEveryone and his/her dog writes Java
18
Java libraries: NLPStanford Parser is the NLP library of choice
19
Java libraries: EmailJavaMail is a better alternative to ActionMailer
20
Access to Java librariesJRuby has deep integration with JavaDirectly call Java code from Ruby
21
Directly calling Java code
22
Using other languagesOther languages built on the JVM• Scala - special support• Clojure• Groovy
23
Using Ruby gemsIf you’re lucky, someone has made a Ruby gem that wraps the Java libraryAlso wrapping a gem is a good idea
24
Easier app deploymentNot easier than git push heroku masterOnly relevant if you’re deploying to large server system
25
Easier app deploymentLeverage existing Java-based deployment infrastructure
26
Leverage infrastructureWarbler packages everything into a single WAR fileStandard file format for Java deploys
27
Other deployment optionsTorqueBox provides additional services
28
Better performanceBetter compiler than MRIBenefits from improvements to JVM
29
Better performanceAccess to highly optimized Java libraries
30
The Bad
Gem availability
32
Gem availabilityGems written in pure Ruby work with JRubyGems with C extensions don’t work with JRubyTypically, these are older, less-maintained gems
33
Fixing gemsSometimes, you can fix the existing gemCould be as simple as replacing its dependenciesOr could be complex
34
Fixing gemsPatched a job queueing systemTook more work than we expectedYMMV
35
Long app startup timeInhibits test-driven developmentDue to Rails startup timeDifficult to set up Spork with JRuby
36
Long app startup timeC’est la vie
37
Less mature technologyMRI still the defaultThough JRuby has maturedLibraries developed against MRI
38
The Ugly
Concurrency“Concurrency is when several computations are executing simultaneously, and potentially interacting with each other.” - Wikipedia
40
ConcurrencyJRuby has real threadsMRI Ruby has threads with Global Interpreter Lock
41
Concurrency and RubyThreads are a major innovation But MRI has never really had a focus on concurrency
42
Concurrency is greatCheaper to scaleGood multi-threaded web servers
43
More bang for your buckOne server: MRI runs two Ruby processesOne server: JRuby runs two Ruby processes with 4 threads eachCan use JRuby on Heroku
44
Concurrency is not freeBugs in non-thread safe libraries• Rails• AirbrakeLibraries developed without a focus on concurrency
45
Concurrency is not freeWriting thread-safe code is difficultEven for Java developers with experienceBut concurrency is the new sexy
46
Concurrency is worth itHuge performance improvementsSome features would be much easier with threadsThreads is the future
47
The Decision
JRuby is a non-standard choice.
Should you use JRuby?Do you want to use Java libraries?
50
Should you use JRuby?Do you want to leverage Java-based deployment infrastructure?
51
Should you use JRuby?Do you need good performance?
52
Should you use JRuby?Otherwise, no
53
Should you use JRuby?Not to worry - you can always switch to JRuby laterLots of people switch for performance reasons
54
Getting started with JRubyjruby-lint checks how ready your code is to run on JRuby
55
AcknowledgmentsPivotal LabsJRuby team
56
Thanks!@MsFionaTay