JRuby State of the Art! 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/).
The JRuby Guys Tom Enebo and Charles Oliver Nutter tom_enebo and headius on Twitter 4-6 years as JRuby devs 2.5 years at Sun Microsystems 12+ years as Java devs Working from home (Minneapolis area)
Basic Facts JRuby 1.2.0 or JRuby 1.3.0RC1 Ruby 1.8.6 or 1.9.1 compat --1.9 flag to use 1.9 mode Rubygems, Rake, Rspec preinstalled Simple install Download bin tarball Unpack Put bin/ dir in PATH http://www.jruby.org
Why Ruby on JVM Best memory management Dynamic optimizations Reliable native threads Vast numbers of libraries Interop with Java, Scala, Rhino (JS), Jython, … Ubiquitous Why not?
JRuby and the JVM AST (interpreter) App code Java calls JRuby Runtime Parser Ruby stdlib Compiler Core classes (String, etc) Precompiled code .class loading Bytecode Java calls
Performance JRuby compiles Ruby to JVM bytecode JVM compiles bytecode to native Native code is optimized, inlined Fastest production-ready implementation
The Magic of Hotspot Vector v = new Vector(3); // Thread-safe list .... reset(v); // Called many times void reset(Vector v) { for (int i = 0; i < v.size(); i++) { v.set(i) = 0; }
Hotspot: Method inlining Inline void reset(Vector v) { fast_guard(v) { for (int I = 0; I < lock { arr.length }; i++) { lock { arr[i] = 0; } }
Hotspot: Simple Optz Unroll Loop void reset(Vector v) { fast_guard(v) { lock { arr[0] = 0; } lock { arr[1] = 0; } lock { arr[2] = 0; } }
Hotspot: Lock Coarsening Coarsen Locks void reset(Vector v) { fast_guard(v) { lock { arr[0] = 0; arr[1] = 0; arr[2] = 0; }
Hotspot: ArrayCopyStub Contiguous Array replaced by Array Copy Stub void reset(Vector v) { fast_guard(v) { lock { arrayCopyStub(v, [0,0,0]) }
Future JVM Work “invokedynamic” New features in Java 7 for dynamic languages Fast dynamic calls...as fast as Java JRuby support by June Multi-language VM “Da Vinci Machine” Optimized tail calls Continuations Fixnums, value types Faster, faster, always faster!
Threading Only production-ready impl with real threads Ruby threads 1:1 native threads Scale across cores, no forks necessary One JRuby server process for an entire site
Simple Rails App Simple 1 controller, 1 model, 1 view app Send 1000 reqs with concurrency 10 (ab) GlassFish v2
Better Deployment The GlassFish gem gem install glassfish Run 'glassfish' in app dir Fast HTTP serving + load balancing One process per application Apache, nginx: just use mod_proxy
Ruby 1.9 Support Probably 80-90% complete IO, Enumerable, some encoding stuff missing IRB works, RubyGems works Lack of Rubyspecs for 1.9 Number one way you could help
FFI Foreign Function Interface Call C functions directly from Ruby Portable, unlike extensions Most extensions just wrap a library Started in Rubinius JRuby added support in 1.1.4 JRuby team: Ruby FFI gem gem install ffi
require 'ffi' module POSIX extend FFI::Library # not usually necessary since libc is always linked ffi_lib 'c' attach_function :getuid, :getuid, [], :uint attach_function :getpid, :getpid, [], :uint end puts "Process #{POSIX.getpid}, user #{POSIX.getuid}"
Who Uses JRuby?
Making the connection Sun's Project Kenai A web platform of best-of-breed integrated collaborative “services” Source code management Subversion, Git, Mercurial Issue/bug tracking Jira, Bugzilla Discussions (mailing lists & forums) Wiki, feeds and aggregators Content management & publishing Building the Web, Using the Web http://kenai.com Sun's Project Kenai
Sun's Kenai on JRuby Rails picked: Quick Development Rapid Changes based on Customer feedback Sun does more than just Java (the language) JRuby picked: Fits Sun software stack better (Java, Glassfish) Wanted to demonstrate how JRuby can scale
Game Designers Gravitor (http://tinyurl.com/gravitor) A “real” game! JRuby for game logic Java for graphics library Packaged as Mac, Windows app King Pong Ruby wrapping JMonkeyEngine
Mission-Critical Apps Oslo's Gardermoen Airport Refueling service JRuby wrapping SWT, touchscreen libraries Completed user acceptance, in production soon
ThoughtWorks Mingle on JRuby Agile Project Management and Team Collaboration Tool Reasons for JRuby on Rails: No Cross Platform SVN library for Ruby Bundling of installation (installer) Security (encrypting source code) Memory profile Avoiding process proliferation http://studios.thoughtworks.com/mingle-project-intelligence
Oracle Mix on JRuby Idea collaboration tool for customers/employees JRuby on Rails: Agile: 5 developers 6 weeks for all development Concise: LOC: 2887, Test LOC: 3691 Needed to integrate in Oracles environment Java, Oracle DB Same group is now writing second application with JRuby on Rails https://mix.oracle.com/
Trisano Open Source Infectious Disease Reporting System Battling Swine Flu as we speak JRuby on Rails reasons: Ease of deployment Every enterprise on the planet runs Java Development team has a Java heritage Roadmap for the project is extensive and they wanted the fall back language to be Java rather than C. http://www.trisano.org
JRuby on Google App Engine GAE deploys WAR files Warbler + jruby-rack DataMapper wrapper for BigTable Automatic up/down scaling JRuby 1.3.0 includes fixes for GAE Updates for related projects coming soon Talk tomorrow at 11:45AM
JRuby on GAE Hackathon! Fun Fun Fun!
Open Q/A Ask anything, we'll answer or demo No question is too dumb/simple/obvious Catch us later if we run out of time