2. JRuby on Google App Engine
Extending the Java Platform & APIs
John Woodell
Nov 27, 2009
2
Wednesday, November 25, 2009
3. What is Google App Engine?
• A cloud-computing platform
• We provide the container and services
• Run your web apps on Google’s infrastructure
• Pay-as-you-go, with free quota to get started
3
Wednesday, November 25, 2009
5. Quotas and Billing
Resource Provided Free Additional Cost
CPU time 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
5
Wednesday, November 25, 2009
6. JRuby on App Engine
6
Wednesday, November 25, 2009
7. 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 , but you have all that you need
+ = ?
7
Wednesday, November 25, 2009
8. $ sudo gem install google-appengine
Successfully installed appengine-rack-0.0.4
Successfully installed appengine-jruby-jars-0.0.6
Successfully installed appengine-sdk-1.2.6
Successfully installed appengine-tools-0.0.6
Successfully installed google-appengine-0.0.6
5 gems installed
Installing ri documentation for appengine-rack-0.0.4...
Installing ri documentation for appengine-jruby-jars-0.0.6...
Installing ri documentation for appengine-sdk-1.2.6...
Installing ri documentation for appengine-tools-0.0.6...
Installing ri documentation for google-appengine-0.0.6...
Installing RDoc documentation for appengine-rack-0.0.4...
Installing RDoc documentation for appengine-jruby-jars-0.0.6...
Installing RDoc documentation for appengine-sdk-1.2.6...
Installing RDoc documentation for appengine-tools-0.0.6...
Installing RDoc documentation for google-appengine-0.0.6...
8
Wednesday, November 25, 2009
10. 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
10
Wednesday, November 25, 2009
11. 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)
• Admin Console
– dashboards
– manage multiple versions
– view logs
11
Wednesday, November 25, 2009
13. Users API
• Existing User Account
• Restrict your app to a domain
map '/src' do
use AppEngine::Rack::AdminRequired
use AppEngine::Rack::SSLRequired
run ActionController::Dispatcher.new
end
map '/' do
run ActionController::Dispatcher.new
end
13
Wednesday, November 25, 2009
15. Memcache API
• No configuration required
• Same API as Ruby-Memcache
• Keys can be any Symbol or String
• Can store any Marshalable or Serializable object
cache = AppEngine::Memcache.new
cache.set_many({:a => 1, :foo => 1..5})
a, foo = cache.get(:a, :foo)
15
Wednesday, November 25, 2009
16. URL Fetch API
• Drop-in replacement for Net::HTTP
AppEngine::URLFetch.fetch(url, options={})
:method
:payload
:headers
:allow_truncated
:follow_redirects
:deadline
16
Wednesday, November 25, 2009
17. Small & Modular Frameworks
• Rack
• Sinatra
• Merb/Rails3*
• Duby
* Currently unreleased
17
Wednesday, November 25, 2009
18. DataMapper Finders
# Comparisons you’d expect
Zoo.first(:name => 'Galveston')
# The 'gt/lt' means greater/less-than.
Person.all(:age.gt => 30)
Person.all(:age.lt => 40)
# The 'gte/lte' means greather/less-than-or-equal-to.
Person.all(:age.gte => 30)
Person.all(:age.lte => 40)
# The value of a pair is an Array
Person.all(:name => 'Sam', :id => [ 1, 2, 3, 4, 5 ])
Person.all(:name => [ 'bob', 'rick', 'steve' ])
# Ordering
Person.all(:order => [ :age.desc ])
18
Wednesday, November 25, 2009
19. DataMapper Associations
• has n, has 1
• belongs_to, many_to_one
class Post
include DataMapper::Resource
property :id, Serial
property :message, Text
has n, :comments
end
class Comment
include DataMapper::Resource
property :id, Serial
property :message, Text
belongs_to :post
end
19
Wednesday, November 25, 2009
21. Resources
• 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/
21
Wednesday, November 25, 2009