jruby and google app engine

29
JRuby By Josh Moore

Upload: joshsmoore

Post on 13-May-2015

3.471 views

Category:

Technology


6 download

DESCRIPTION

Introduction to JRuby and also running Rails on the Google App Engine.

TRANSCRIPT

Page 1: JRuby and Google App Engine

JRuby

By Josh Moore

Page 2: JRuby and Google App Engine

Who am I

Josh Moorewww.codingforrent.comtwitter.com/codingforrenthttp://github.com/joshsmoore

RubyWatir at workRails on the Google App Engine for hobby

maintain rails_dm_datastore gem

Page 3: JRuby and Google App Engine

Contents

What is JRuby?Quick compare to MRI 1.8.7 and 1.9.1Gem CompatibilityJava IntegrationPerformanceJRuby on RailsShort comingsGoogle App Engine

Page 4: JRuby and Google App Engine

What is JRuby

Ruby interpreter on top of the JVMStarted in 2001Runs rails in 2006

Compatible syntax1.8.7/1.9.1(mostly)

Page 5: JRuby and Google App Engine

Quick ComparisonMRI 1.8.7 MRI 1.9.1 JRuby

Gems Compatible Fairly Compatible Fairly Compatible

Rails yes yes (Rails3) yes

Speed slowGreen threads

fastnative threads

medium to fastnative threads

Pros Compatibility FastBetter syntax?

medium FastJava integrationRuby 1.8.x and 1.9 syntax

Cons Slow ruby compatibility problems

C extension with compatibility problems

Page 6: JRuby and Google App Engine

Ruby Gems

Pure Ruby gems, no problemGems with C extensions, have problems

C extensions can work if invoked using the Foreign Function Invocation interface.

Nokogiri Switch to using Java instead of C

HpricotSome gems are JRuby only

Jemini

Page 7: JRuby and Google App Engine

Performance

Performance numbers using this project

Page 8: JRuby and Google App Engine

Java Integration - LibrariesAny library in the classpath can be accessedMaven is a Build/depedency management to for Java, acts like gems in ruby

Similar to rake and gems put togetherGemcutter - 10,467 gemsMaven - 158,643 archives, thats a lotComing with JRuby 1.5.0

Page 9: JRuby and Google App Engine

Java Integration - Code

nil == nullself == thisJava interfaces mapped to modulesto_java converts ruby objects to Java objectsCloser Convention

Implement Java interfaces as blocks

b = JButton.new('click me')

b.add_action_listener do |event| JOptionPane.show_message_dialog nil, "Clicked"end

Page 10: JRuby and Google App Engine

Java Integration - Code

JavagetA and setA

Java in JRubya and a=

Javanew Object(1)

Java in JRubyObject.new 1

Getters and Setters

Object Creation

Page 11: JRuby and Google App Engine

Demo 1

Swing UI in Ruby

Page 12: JRuby and Google App Engine

JVM Benefits

World class garbage collectionPerformanceNative Threads (really run rails in parallel)Pretty much runs on any hardware

Page 13: JRuby and Google App Engine

JVM Optimization

Page 14: JRuby and Google App Engine

JVM Optimization

Page 15: JRuby and Google App Engine

Rails

It just works (like most pure ruby libraries)Only deployment is different

you can actually deploy and test in MRI and then deploy using JRubydeploy using warbler

Page 16: JRuby and Google App Engine

Deploying Rails

Packaged into WAR (Web Application Archive)Deployable on any Java Application server, or any Java hosting service.Including cloud hosting like Google App Engine

Page 17: JRuby and Google App Engine

Known Problems

ObjectSpace is disabledSlower startup timeC extension incompatibilities

Page 18: JRuby and Google App Engine

Rails on the Google App Engine

By Josh Moore

Page 19: JRuby and Google App Engine

What is it?

Cloud hosting solution provided by Google.Even more "cloudish" (ie less control and even easier scaling) then heroku

All you do is submit your code and it runs you have no control over where it runs or what it is running on or even how many instances are running.Getting lots of request GAE simply starts up more instances of your app automatically.Computer resources scaled 100% dynamicallyBuilt for scalability, including sharding of data

Page 20: JRuby and Google App Engine

Architecture

Page 21: JRuby and Google App Engine

Persistence - Datastore

No RDMSDatastore

FastNot a relational databaseNo SQL, GQL insteadSome fast SQL operations are slow

Sums/counts are not really efficient so it is best to keep running totals.Joining can be very inefficient

All these differences can be overcome, it just requires a paradigm shift.

Page 22: JRuby and Google App Engine

Strengths

Fluid scalability no configuration required

Fairly complete API setPersistence designed for scalabilityEverything designed for dynamic scalabilityNo need to worry about or configure anything on the server side

Page 23: JRuby and Google App Engine

The Downsides/Restrictions

Officially Java and PythonRuby support not official

RestrictiveOnly 30 seconds per request (spin up time)Only one set of rulesCannot write to file system from appCode restrictions

No Threads and other API restrictionsAbsolutely no C code

Page 24: JRuby and Google App Engine

JRuby on GAE

Tools - http://code.google.com/p/appengine-jruby/Project Run by John Woodell (Google employee)Also wraps the local development environment

Work from MRI 1.8.7no need to mess with jruby

Provide API wrappers for google servicesRack adapter - Rails, Sinatra, or custom

Rails patches providedDatamapper adapter

No ActiveRecord

Page 25: JRuby and Google App Engine

Rails

Some Modification requiredDatamapper basedTinyDS based

Page 26: JRuby and Google App Engine

Demo 2

Page 27: JRuby and Google App Engine

Why do I use JRuby and GAE

I Learned Java in CollegeLike to atleast have a chance of knowing what is going on under the hood

GAEStill in its infancy so still lots of work to be done

Page 28: JRuby and Google App Engine

Question?

Page 29: JRuby and Google App Engine

http://api.wefeelfine.org:8080/ShowFeelings?returnfields=feeling&limit=1&conditions=1

http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=yarv&lang2=ruby

http://blog.pluron.com/2009/05/ruby-19-performance.html

http://blog.headius.com/2009/04/how-jruby-makes-ruby-fast.html

http://github.com/acangiano/ruby-benchmark-suite

http://www.jarvana.com/jarvana/info/repository_statistics