This document discusses JRuby and Duby for running Ruby and Ruby-like applications on Google App Engine. It introduces Google App Engine as a platform-as-a-service that handles scaling and infrastructure. JRuby allows running Ruby applications on App Engine by compiling to Java bytecode. Duby is a new language that compiles to Java and has Ruby-like syntax, avoiding runtime issues. Examples show how to create a simple blog application in Duby using App Engine services and data modeling.
4. What is Google App Engine?
• A cloud-computing platform
• Run your web apps on Google’s infrastructure
• We provide the container and services (PaaS)
– Hardware, connectivity
– Operating system
– JVM
– Servlet container
– Software services
4
Wednesday, November 18, 2009
5. Key Features
• No need to install or maintain your own stack
• We do the scaling for you
• Use Google’s scalable services via standard APIs
• Charge only for actual usage
– Always free to get started
• Built-in application management console
5
Wednesday, November 18, 2009
6. App Engine Architecture
Incoming Requests
Load App Engine App Engine App Engine
Balancer Front End Front End Front End
AppServer AppServer AppServer
Other Google
AppServer Infrastructure
API Layer - Bigtable
- Google Accounts
- Memcache
App App App
- Image manipulation
6
Wednesday, November 18, 2009
7. Traditional Ruby App Server Strategy
• Load everything into memory, servers can sit idle
• The “big box” database strategy, will eventually hit a wall
• Ruby and C extensions, portability issues, fewer APIs
• Allocate and administer machines, manage load balancers
7
Wednesday, November 18, 2009
8. JRuby on App Engine Strategy
• Load only what you need for each new instance
• Distributed persistence layer... simple and scalable
• JRuby and Java, catch exceptions and use first-class APIs
• Only worry about your application code in the container
8
Wednesday, November 18, 2009
10. Quotas and Billing
Resource Provided Free Additional Cost
CPU 6.5 hours/day $0.10/hour
Bandwidth In 1GByte/day $0.10/GByte
Bandwidth Out 1GByte/day $0.12/GByte
Stored Data 1 GB $0.005/GB-day
Emails sent 2000/day to users $0.0001/email
50000/day to admins
10
Wednesday, November 18, 2009
11. JRuby on App Engine
11
Wednesday, November 18, 2009
12. Easy to Install
sudo gem install google-appengine
Everything you need installs as gems
12
Wednesday, November 18, 2009
13. Support for JRuby
• Can outperforms MRI in many cases
• Gem extensions written in Java (no more segfaults)
• A wealth of integration options available
• Already works on App Engine with supported APIs
13
Wednesday, November 18, 2009
14. Support for Sinatra Microframework
• No learning curve... a simple and elegant DSL
• Some data-driven apps don’t require MVC or ActionView
• No need to extract the components we can’t use
• New application instances can spin up quickly
14
Wednesday, November 18, 2009
15. Support for Rails3
• More modular, load only what you need for each request
• Intelligent gem management and deployment tools
• First-class integrations with “other” ORMs like DataMapper
• Better routing and Rack integration
• Better Javascript integration and options
• Rails conventions!
15
Wednesday, November 18, 2009
16. Support for DataMapper
• Data mapped in your model, auto-migrations or no migrations
• Text fields treated like associations, lazy-load by default
• Create concise queries without using method_missing
• Supports validations and legacy AR finders
• Already works with dm-appengine wrapper
16
Wednesday, November 18, 2009
17. Support for Servlet 2.5 Spec
• Everything you need in in the container
• JRuby-Rack dispatches to Rack
while providing access to servlet features
• Access to Google App Engine APIs for Java
via Ruby APIs that are feature compatible
• Our tools allow you to develop in the container
with the ability to integrate Java servlets
17
Wednesday, November 18, 2009
19. Dev AppServer
• Customized Jetty server
• Local implementation of services
– LRU memcache
– Disk-backed datastore
– HttpClient-backed URLFetch
• Emulates the production environment
– Sandbox restrictions may be inconsistent,
so run tests on production servers as well
19
Wednesday, November 18, 2009
20. Deployment
• Your app lives at
– <app_id>.appspot.com, or
– Custom domain with Google Apps
• Deploying uploads
– Static files
– Resource files
– Other metadata (datastore indexes, cron jobs)
20
Wednesday, November 18, 2009
21. Administration
• Admin Console
– Invite others to be developers
– Browse your datastore & manage indexes
– View access data & error logs
– Analyze traffic
– View the status of scheduled tasks
– Test new versions of your app
21
Wednesday, November 18, 2009
22. Demo
run lambda { |env| [200, {}, 'Hello'] }
22
Wednesday, November 18, 2009
23. Current Issues with JRuby on App Engine
• Several seconds to “spin-up” a new JRuby instance
• Some gems still need their extensions ported to Java
• Not an officially supported platform
23
Wednesday, November 18, 2009
25. Duby has Ruby-inspired Syntax
def fib(a:int)
if a < 2
a
else
fib(a - 1) + fib(a - 2)
end
end
puts fib 10
Wednesday, November 18, 2009
26. // Generated from examples/Test.duby
public class Test extends java.lang.Object {
public static void main(String[] argv) {
System.out.println(Test.fib(10));
}
public static int fib(int a) {
return (a < 2) ?
(a) :
((Test.fib((a - 1)) + Test.fib((a - 2))));
}
}
Wednesday, November 18, 2009
27. Duby’s not Ruby
• Statically typed
• No Duby runtime
• Uses Java’s type system
27
Wednesday, November 18, 2009
28. A Simple Duby App
import javax.servlet.http.HttpServlet
import com.google.appengine.ext.duby.db.Model
class Post < Model
def initialize; end
property title, String
property body, Text
end
class DubyApp < HttpServlet
def_edb(list, 'com/ribrdb/list.dhtml')
def doGet(request, response)
@posts = Post.all.run
response.getWriter.write(list)
end
def doPost(request, response)
post = Post.new
post.title = request.getParameter('title')
post.body = Text.new(request.getParameter('body'))
post.save
doGet(request, response)
end
end
28
Wednesday, November 18, 2009
29. A Simple Duby App
import javax.servlet.http.HttpServlet
import com.google.appengine.ext.duby.db.Model
class Post < Model
def initialize; end
property title, String
property body, Text
end Types
class DubyApp < HttpServlet inferred from parent
def_edb(list, 'com/ribrdb/list.dhtml')
class
def doGet(request, response)
@posts = Post.all.run
response.getWriter.write(list)
end
def doPost(request, response)
post = Post.new
post.title = request.getParameter('title')
post.body = Text.new(request.getParameter('body'))
post.save
doGet(request, response)
end
end
29
Wednesday, November 18, 2009
30. A Simple Duby App
import javax.servlet.http.HttpServlet
import com.google.appengine.ext.duby.db.Model
class Post < Model
def initialize; end
property title, String
property body, Text
end
Plugins
class DubyApp < HttpServlet
def_edb(list, 'com/ribrdb/list.dhtml')
def doGet(request, response)
@posts = Post.all.run
response.getWriter.write(list)
end
def doPost(request, response)
post = Post.new
post.title = request.getParameter('title')
post.body = Text.new(request.getParameter('body'))
post.save
doGet(request, response)
end
end
30
Wednesday, November 18, 2009
31. Duby Supports Plugins
Only form of metaprogramming (for now)
require 'erb'
Duby::AST.defmacro('def_edb') do |duby, fcall, p|
name = fcall.args_node.get(0).name
path = fcall.args_node.get(1).value
erb = ERB::Compiler.new(nil)
...
src = erb.compile(IO.read(path))
duby.eval(src, p, “(edb)”)
end
Wednesday, November 18, 2009
32. Duby Can Use erb Templates
<title>Posts</title>
<body>
<h1>All Posts:</h1>
<% for post in @posts %>
<h2><%= post.title %></h2>
<p><%= post.body.getValue %></p>
<% end %>
<hr>
<h1>New Post:</h1>
<form method=post>
Title: <input type=text name=title><br>
Body: <textarea name=body></textarea><br>
<input type=submit>
</form>
</body>
Wednesday, November 18, 2009
33. More to Come
• Open classes
• Mix ins
• Blocks
• More
33
Wednesday, November 18, 2009
34. Resources
• Ryan Brown, ribrdb@google.com
John Woodell, woodie@google.com
• Google App Engine for JRuby
– http://code.google.com/p/appengine-jruby/
• Google Group
– http://groups.google.com/group/appengine-jruby
• Blog: JRuby on App Engine Blog
– http://jruby-appengine.blogspot.com/
34
Wednesday, November 18, 2009