jruby on appengine

41
budapest.rb JRuby on AppEngine Janos Hardi [email protected]

Upload: janos-hardi

Post on 12-May-2015

3.952 views

Category:

Technology


0 download

DESCRIPTION

A meetup talk given at budapest.rb http://www.meetup.com/budapest-rb/

TRANSCRIPT

Page 1: JRuby on Appengine

budapest.rb

JRuby on AppEngine

Janos [email protected]

Page 2: JRuby on Appengine

Agenda

JVM

Scripting on the JVM

JRuby

Rack

Google AppEngine/Java

Experiences

Page 3: JRuby on Appengine

JVM

Java Language != Java Platform

Platform Independence

Rich Class System

Open Source

Page 4: JRuby on Appengine

JVM

Java Runtime Environment

JVM JVM JVM

App App App

Page 5: JRuby on Appengine

JVM

http://www.artima.com/insidejvm/ed2/jvm2.html

Page 6: JRuby on Appengine

JVM

Fine tuneability

Extensibility

Stable

Admin interfaces

Safe code sharing

Page 7: JRuby on Appengine

Scripting on the JVM

Python (Jython - http://www.jython.org)

Ruby (JRuby - http://www.jruby.org)

Lisp (Clojure - http://clojure.org)

JavaScript (Rhino - http://www.mozilla.org/rhino/)

PHP (IBM - P8 / Caucho - Quercus)

Scala (http://www.scala-lang.org)

And many many more

Page 8: JRuby on Appengine

Scripting on the JVM

How?

Page 9: JRuby on Appengine

Scripting on the JVM

JSR-223

import javax.script.*

http://scripting.dev.java.net/http://developers.sun.com/scripting/

Page 10: JRuby on Appengine

Scripting on the JVM

Java Runtime Environment

JVM

App

Scripting

JRuby

Page 11: JRuby on Appengine

Scripting on the JVM

Why?

Page 12: JRuby on Appengine

Scripting on the JVM

Rapid app development

Special needs, eg. at liligo.com ;)

Integration

Page 13: JRuby on Appengine

JRuby

Ruby for JavaRuby in Java

Page 14: JRuby on Appengine

JRuby

Native Threads

Garbage Collector

Embeddability

No fork

No C extensions

Page 15: JRuby on Appengine

Rack

Rails, Merb, Sinatra, Camping, Ramaze ...

CGI, FCGI, Mongrel, Thin, Webrick, Litespeed ...

Page 16: JRuby on Appengine

Rack

class HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] endend

Page 17: JRuby on Appengine

Rack

Simple Ruby API modelling HTTP

Standard interface between frameworks and handlers

Interface for injecting middlewares

Page 18: JRuby on Appengine

Rack

WSGI for Rubyhttp://chneukirchen.org/talks/#introducingrack

http://wiki.github.com/rack/rack

Page 19: JRuby on Appengine

JRuby-Rack

WSGI for JRuby

Rack + Java Servlet ContainersTomcat, Glassfish, Jetty ...

Page 20: JRuby on Appengine

<context-param> <param-name>rackup</param-name> <param-value> require 'rubygems' require 'app' set :environment, :production set :run, false run Sinatra::Application </param-value></context-param> <filter> <filter-name>RackFilter</filter-name> <filter-class>org.jruby.rack.RackFilter</filter-class> </filter> <filter-mapping> <filter-name>RackFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.jruby.rack.RackServletContextListener </listener-class> </listener>

Page 21: JRuby on Appengine

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <context-param> <param-name>public.root</param-name> <param-value>/</param-value> </context-param> <filter> <filter-name>RackFilter</filter-name> <filter-class> org.jruby.rack.RackFilter </filter-class> </filter> <filter-mapping> <filter-name>RackFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.jruby.rack.merb.MerbServletContextListener </listener-class> </listener></web-app>

Page 22: JRuby on Appengine

JRuby-Rack

Java Runtime Environment

JVM

App

FrameworkJRuby

Servlet container

Rack

Page 23: JRuby on Appengine

Google AppEngine/Java

What?

Page 24: JRuby on Appengine

Google AppEngine/Java

App stack

App hosting

Development environment

Great API system

A bunch of services

for free ...

Page 25: JRuby on Appengine

GAE/J – App stack

Automatic scaling

Write your App only

Everything else happens on APIs

External APIs with URL Fetch

Page 26: JRuby on Appengine

GAE/J – App hosting

10 app / google user

Admin interface

Cron

Quota is OK

Logging

Page 27: JRuby on Appengine

GAE/J – App hosting

Page 28: JRuby on Appengine

GAE/J – App hosting

Page 29: JRuby on Appengine

GAE/J – App hosting

Page 30: JRuby on Appengine

GAE/J – Dev environment

App server

Deployment

App versions

Multiple developer accounts

Good examples

SDK

Plugins (Eclipse IDE)

Page 31: JRuby on Appengine

GAE/J – APIs / Services

Memcache

Datastore

Mail

Image

Google account

URL Fetch

Page 32: JRuby on Appengine

GAE/J - Datastore

Schemaless

Object oriented

Key / Value

Universal

< Entity ( Story (1) ) >

Page 33: JRuby on Appengine

Experiences

Slow warmup (JRuby + AppEngine)

Nice performance after App cache

CPU intensive operations

Almost unusable Dev tools

Rare libs for GAE/J APIs

No migration (bulk loader is 404!)

Page 34: JRuby on Appengine

Experiences

JRuby-AppEngine (low level wrapper for almost all APIs)

Bumble (minimal lib for the Datastore)

Datamapper (with JRuby-AppEngine)

Warbler (for deployment)

Page 35: JRuby on Appengine

JRuby-AppEngine

post '/story/add' do @story = Datastore::Entity.new('Story') @story['title'] = params[:title] @story['slug'] = params[:slug] @story['body'] = Datastore::Text.new( params[:body] ) Datastore.put(@story) redirect '/stories'end

Page 36: JRuby on Appengine

Bumbleclass Person include Bumble ds :given_name, :sur_name, :email has_many :blogs, Blog, :owner_idend

class Blog include Bumble ds :name, :owner_id, :created_at belongs_to :owner, Person has_many :posts, :Post, :blog_id, :iorder => :created_atend

class Post include Bumble ds :title, :content, :created_at, :blog_id belongs_to :blog, Blogend

Page 37: JRuby on Appengine

Warbler

Warbler::Config.new do |config| config.dirs = %w(lib views models) config.includes = FileList["appengine-web.xml", "app.rb", "config.ru"] config.gems = ['sinatra', 'haml','appengine-apis','maruku'] config.gem_dependencies = true config.war_name = "test" config.webxml.booter = :rack config.webxml.jruby.min.runtimes = 1 config.webxml.jruby.max.runtimes = 1 config.webxml.jruby.init.serial = true config.java_libs = []end

Page 38: JRuby on Appengine

Components

Appengine account

GAE/J SDK

JRuby 1.3.1

JRuby-Rack

Gems

GAE/Merb Example Application ;)http://github.com/yaanno/gae-merb-example

Page 39: JRuby on Appengine

Merb flat app

WEB-INF appengine-web.xml web.xml application.rb config framework.rb init.rb lib appengine-api-sdk.jar gems.jar jruby-complete.jar jruby-rack.jar views index.haml

Page 40: JRuby on Appengine

Thanks

Page 41: JRuby on Appengine

A few useful links

http://www.infoq.com/presentations/nicholson-php-jvmhttp://www.artima.com/insidejvm/ed2/index.htmlhttp://code.google.com/appengine/http://blog.headius.comhttp://blog.nicksieger.comhttp://olabini.com/blog/http://isitjruby.com/http://code.google.com/events/io/sessions.html#appengine