why jruby?

57
Why JRuby? Fiona Tay @msfionatay Engineer, Pivotal Labs

Upload: fiona-tay

Post on 16-May-2015

11.403 views

Category:

Technology


0 download

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

Page 1: Why JRuby?

Why JRuby?Fiona Tay @msfionatayEngineer, Pivotal Labs

Page 2: Why JRuby?

This is for the person who just wants to make web apps.

Page 3: Why JRuby?

This is about the Good, The Bad, and The Ugly.

Page 4: Why JRuby?

I’m a Rubyist

4

Page 6: Why JRuby?

An Introduction

Page 7: Why JRuby?

It’s a Ruby implementation1. Install it2. Write Ruby code

7

Page 8: Why JRuby?

It’s a Ruby implementation

8

Page 9: Why JRuby?

Ruby implementationsInterchangeable to an extentPopular implementations:• MRI• JRuby• Rubinius • MacRuby

9

Page 10: Why JRuby?

Under the hood

10

 

Page 11: Why JRuby?

Under the hood

11

 

secret sauce

Page 12: Why JRuby?

Interchangeability1+1 should be 2 in all implementations

12

Page 13: Why JRuby?

Implementation differencesSome implementations are more equal than others Differences:• Speed of execution• Support for libraries• Implementation bugs

13

Page 14: Why JRuby?

History of JRubyAround since 2002Has had traction in real projects since ~2005

14

Page 15: Why JRuby?

JRuby in the real world

15

Page 16: Why JRuby?

JRuby in the real world

16

Page 17: Why JRuby?

The Good

Page 18: Why JRuby?

Access to Java librariesIncredibly powerful toolEveryone and his/her dog writes Java

18

Page 19: Why JRuby?

Java libraries: NLPStanford Parser is the NLP library of choice

19

Page 20: Why JRuby?

Java libraries: EmailJavaMail is a better alternative to ActionMailer

20

Page 21: Why JRuby?

Access to Java librariesJRuby has deep integration with JavaDirectly call Java code from Ruby

21

Page 22: Why JRuby?

Directly calling Java code

22

Page 23: Why JRuby?

Using other languagesOther languages built on the JVM• Scala - special support• Clojure• Groovy

23

Page 24: Why JRuby?

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

Page 25: Why JRuby?

Easier app deploymentNot easier than git push heroku masterOnly relevant if you’re deploying to large server system

25

Page 26: Why JRuby?

Easier app deploymentLeverage existing Java-based deployment infrastructure

26

Page 27: Why JRuby?

Leverage infrastructureWarbler packages everything into a single WAR fileStandard file format for Java deploys

27

Page 28: Why JRuby?

Other deployment optionsTorqueBox provides additional services

28

Page 29: Why JRuby?

Better performanceBetter compiler than MRIBenefits from improvements to JVM

29

Page 30: Why JRuby?

Better performanceAccess to highly optimized Java libraries

30

Page 31: Why JRuby?

The Bad

Page 32: Why JRuby?

Gem availability

32

Page 33: Why JRuby?

Gem availabilityGems written in pure Ruby work with JRubyGems with C extensions don’t work with JRubyTypically, these are older, less-maintained gems

33

Page 34: Why JRuby?

Fixing gemsSometimes, you can fix the existing gemCould be as simple as replacing its dependenciesOr could be complex

34

Page 35: Why JRuby?

Fixing gemsPatched a job queueing systemTook more work than we expectedYMMV

35

Page 36: Why JRuby?

Long app startup timeInhibits test-driven developmentDue to Rails startup timeDifficult to set up Spork with JRuby

36

Page 37: Why JRuby?

Long app startup timeC’est la vie

37

Page 38: Why JRuby?

Less mature technologyMRI still the defaultThough JRuby has maturedLibraries developed against MRI

38

Page 39: Why JRuby?

The Ugly

Page 40: Why JRuby?

Concurrency“Concurrency is when several computations are executing simultaneously, and potentially interacting with each other.” - Wikipedia

40

Page 41: Why JRuby?

ConcurrencyJRuby has real threadsMRI Ruby has threads with Global Interpreter Lock

41

Page 42: Why JRuby?

Concurrency and RubyThreads are a major innovation But MRI has never really had a focus on concurrency

42

Page 43: Why JRuby?

Concurrency is greatCheaper to scaleGood multi-threaded web servers

43

Page 44: Why JRuby?

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

Page 45: Why JRuby?

Concurrency is not freeBugs in non-thread safe libraries• Rails• AirbrakeLibraries developed without a focus on concurrency

45

Page 46: Why JRuby?

Concurrency is not freeWriting thread-safe code is difficultEven for Java developers with experienceBut concurrency is the new sexy

46

Page 47: Why JRuby?

Concurrency is worth itHuge performance improvementsSome features would be much easier with threadsThreads is the future

47

Page 48: Why JRuby?

The Decision

Page 49: Why JRuby?

JRuby is a non-standard choice.

Page 50: Why JRuby?

Should you use JRuby?Do you want to use Java libraries?

50

Page 51: Why JRuby?

Should you use JRuby?Do you want to leverage Java-based deployment infrastructure?

51

Page 52: Why JRuby?

Should you use JRuby?Do you need good performance?

52

Page 53: Why JRuby?

Should you use JRuby?Otherwise, no

53

Page 54: Why JRuby?

Should you use JRuby?Not to worry - you can always switch to JRuby laterLots of people switch for performance reasons

54

Page 55: Why JRuby?

Getting started with JRubyjruby-lint checks how ready your code is to run on JRuby

55

Page 56: Why JRuby?

AcknowledgmentsPivotal LabsJRuby team

56

Page 57: Why JRuby?

Thanks!@MsFionaTay