Date post: | 13-May-2015 |
Category: |
Technology |
Upload: | joshsmoore |
View: | 3,472 times |
Download: | 6 times |
JRuby
By Josh Moore
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
Contents
What is JRuby?Quick compare to MRI 1.8.7 and 1.9.1Gem CompatibilityJava IntegrationPerformanceJRuby on RailsShort comingsGoogle 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)
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
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
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
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
Java Integration - Code
JavagetA and setA
Java in JRubya and a=
Javanew Object(1)
Java in JRubyObject.new 1
Getters and Setters
Object Creation
Demo 1
Swing UI in Ruby
JVM Benefits
World class garbage collectionPerformanceNative Threads (really run rails in parallel)Pretty much runs on any hardware
JVM Optimization
JVM Optimization
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
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
Known Problems
ObjectSpace is disabledSlower startup timeC extension incompatibilities
Rails on the Google App Engine
By Josh Moore
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
Architecture
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.
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
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
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
Rails
Some Modification requiredDatamapper basedTinyDS based
Demo 2
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
Question?
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