RubyConf 2009

1,098 views

Published on

Scaling on App Engine with Ruby & Duby

2009-11-20

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,098
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

RubyConf 2009

  1. 1. + × n Saturday, November 21, 2009
  2. 2. Scaling on App Engine with Ruby & Duby John Woodell Ryan Brown Nov 20, 2009 2 Saturday, November 21, 2009
  3. 3. Google App Engine 3 Saturday, November 21, 2009
  4. 4. What is Google App Engine? • A cloud-computing platform • Run your web apps on Google’s infrastructure • Platform as a Services (PaaS) 4 Saturday, November 21, 2009
  5. 5. 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 5 Saturday, November 21, 2009
  6. 6. WhiteHouse.gov/openforquestions 6 Saturday, November 21, 2009
  7. 7. 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 7 Saturday, November 21, 2009
  8. 8. Ruby on App Engine 8 Saturday, November 21, 2009
  9. 9. Apps run on JRuby • Fast and portable • A wealth of integration options • Supported App Engine Java APIs 9 Saturday, November 21, 2009
  10. 10. Small & Modular Frameworks • Rack • Sinatra • Merb/Rails3* • Duby * Currently unreleased 10 Saturday, November 21, 2009
  11. 11. DataMapper for Persistence • Schema defined in your model • Extensions for validations, AR finders & more • Works with existing dm-appengine adapter 11 Saturday, November 21, 2009
  12. 12. Easy to Install sudo gem install google-appengine Everything you need installs as gems 12 Saturday, November 21, 2009
  13. 13. App Engine Gems • Development Gems – appengine-rack – appengine-tools [ appcfg.rb, dev_appserver.rb ] – appengine-sdk – appengine-jruby-jars • Runtime Gems – appengine-rack – dm-appengine – appengine-apis 13 Saturday, November 21, 2009
  14. 14. App Engine JRuby APIs • AppEngine::Users • AppEngine::Datastore • AppEngine::Memcache • AppEngine::Mail • AppEngine::URLFetch • AppEngine::Images • AppEngine::Logger • AppEngine::XMPP • AppEngine::Labs::TaskQueue 14 Saturday, November 21, 2009
  15. 15. Simple XMPP Rack App 15 Saturday, November 21, 2009
  16. 16. Demo run lambda { |env| [200, {}, 'Hello'] } 16 Saturday, November 21, 2009
  17. 17. 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 officially supported 17 Saturday, November 21, 2009
  18. 18. Introducing Duby Saturday, November 21, 2009
  19. 19. Duby’s not Ruby • Statically typed • No Duby runtime • Uses Java’s type system 19 Saturday, November 21, 2009
  20. 20. 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 Saturday, November 21, 2009
  21. 21. // 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)))); } } Saturday, November 21, 2009
  22. 22. 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 22 Saturday, November 21, 2009
  23. 23. 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 23 Saturday, November 21, 2009
  24. 24. 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 24 Saturday, November 21, 2009
  25. 25. 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 Saturday, November 21, 2009
  26. 26. 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> Saturday, November 21, 2009
  27. 27. More to Come • Open classes • Mix ins • Blocks • More 27 Saturday, November 21, 2009
  28. 28. 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/ 28 Saturday, November 21, 2009
  29. 29. + × n Saturday, November 21, 2009

×