Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google 1
Goals > Google App Engine > Java on App Engine > The App Engine Datastore > Demo > Questions 2 2
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 3 3
Key Features > No need to install or maintain your own stack > We scale 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 4 4
App Engine Architecture Incoming Requests 5 5
App Engine Architecture Incoming Requests App Engine Front End App Engine Front End App Engine Front End 5 5
App Engine Architecture Incoming Requests App Engine Front End App Engine Front End App Engine Front End AppServer AppServer AppServer 5 5
App Engine Architecture Incoming Requests Load Balancer App Engine Front End App Engine Front End App Engine Front End AppServer AppServer AppServer 5 5
App Engine Architecture Incoming Requests Load Balancer App Engine Front End App Engine Front End App Engine Front End AppServer AppServer AppServer AppServer Other Google Infrastructure API Layer - Bigtable - Google Accounts App App App - Memcache - Image manipulation 5 5
When To Use Google App Engine > Targeting web applications Serve HTTP requests, limited to 30 seconds No long-running background processes No server push > Sandboxed environment No threads Read-only file system 6 6
WebHooks (coming soon) > Incoming email > XMPP > Google Wave > Task Queues 7 7
Java Support > Servlets > Software services > Sandboxing > DevAppServer > Deployment > Tooling 8 8
Servlet API > Full Servlet 2.5 Container HTTP Session JSP > Uses Jetty and Jasper Powered by Google s HTTP stack No Jetty-specific features Subject to change 9 9
Software Services Service Java Standard Google Infrastructure Authentication Servlet API Google Accounts Datastore JPA, JDO Bigtable Caching javax.cache memcacheg E-mail javax.mail Gmail gateway URLFetch URLConnection Caching HTTP proxy 10 10
Sandboxing > What do we do? Restrict JVM permissions WhiteList classes > Why is it necessary? Clustering - JVMs come and go Protect applications from one another 11 11
Sandboxing Restrictions Restriction Alternative Threads Async and Queue API (Soon!) Direct network connections URLConnection Direct file system writes Memory, memcache, datastore Java2D Images API Software rendering Native code Pure Java libraries 12 12
Flexible Sandboxing 13 13
Flexible Sandboxing JVM Permissions often too coarse. 13 13
Flexible Sandboxing JVM Permissions often too coarse. They either provide a cramped sandbox. 13 13
Flexible Sandboxing JVM Permissions often too coarse. They either provide a cramped sandbox. Or they hand over the nuclear launch codes. 13 13
Flexible Sandboxing JVM Permissions often too coarse. They either provide a cramped sandbox. Or they hand over the nuclear launch codes. App Engine delivers a happy medium. 13 13
Flexible Sandboxing - Reflection 14 14
Flexible Sandboxing - Reflection > Access private fields, call private methods suppressaccesschecks accessdeclaredmembers 14 14
Flexible Sandboxing - Reflection > Access private fields, call private methods suppressaccesschecks accessdeclaredmembers Bad! Field f = String.class.getDeclaredField( count ); f.setaccessible(true); f.set( Hello World, 2); 14 14
Flexible Sandboxing - Reflection > Access private fields, call private methods suppressaccesschecks accessdeclaredmembers Bad! Field f = String.class.getDeclaredField( count ); f.setaccessible(true); f.set( Hello World, 2); Good! Field f = MyClass.class.getDeclaredField( foo ); f.setaccessible(true); f.set(myobj, afoo); 14 14
Flexible Sandboxing - Class Loading 15 15
Flexible Sandboxing - Class Loading > Create user-controlled ClassLoaders createclassloader 15 15
Flexible Sandboxing - Class Loading > Create user-controlled ClassLoaders createclassloader Bad! ClassLoader myclassloader = new URLClassLoader() { public PermissionsCollection getpermissions(codesource cs) { // return AllPermission; } }; 15 15
Flexible Sandboxing - Class Loading > Create user-controlled ClassLoaders createclassloader Bad! ClassLoader myclassloader = new URLClassLoader() { }; public PermissionsCollection getpermissions(codesource cs) { } // return AllPermission; Good! ClassLoader myclassloader = new URLClassLoader() { }; public Class findclass(string classname) { } // define and load some newly generated bytecode 15 15
Flexible Sandboxing - Compatibility > Dependency Injection Frameworks Guice, Spring > Aspect Oriented Programming AspectJ, Spring AOP > Web Frameworks GWT, Tapestry, BlazeDS (Flex), Grails! > Alternate JVM languages Scala, Rhino, JRuby, Jython, Clojure, Groovy, PHP 16 16
DevAppServer > Emulates the production environment > Customized Jetty server > Local implementation of services LRU memcache Disk-backed datastore HttpClient-backed URLFetch > Some sandbox restrictions difficult to emulate 17 17
Deployment > Your app lives at <app_id>.appspot.com, or Custom domain with Google Apps for your Domain > Command line and IDE tools > Admin Console Dashboards Manage multiple versions View logs (java.util.logging) 18 18
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 5000/day to admins $0.0001/email 19 19
Tooling > SDK Tools API Command-line tools, Ant, and IDE plugins > Provides Deployment DevAppServer WhiteList XML validation > Google Eclipse Plugin, Intellij Plugin 20 20
The Datastore Is... > Transactional > Natively Partitioned > Hierarchical > Schema-less > Based on Bigtable > Not a relational db Wow. That is one big table. > Not a SQL engine 21 21
Simplifying Storage > Simplify development of apps > Simplify management of apps > App Engine services build on Google s strengths > Scale always matters Request volume Data volume 22 22
Datastore Storage Model > Basic unit of storage is an Entity consisting of Kind (table) Key (pk) Entity Group (top level ancestor) Has locking implications 0..N typed Properties (columns) 23 23
Interesting Datastore Modeling Features > Ancestor > Multi-value properties > Variable properties > Heterogenous property types Kind Person Entity Group /Person:Ethel Key /Person:Ethel Age Int64: 30 Hobbies String: Tennis Kind Person Entity Group /Person:Ethel Key /Person:Ethel/Person:Jane Age Double: 3.5 Pets Key:/Turtle:Sam Key:/Dog:Ernie 24 24
Datastore Transactions > Transactions apply to a single Entity Group Global transactions are feasible > get(), put(), delete() are transactional > Queries are not transactional (yet) /Person:Ethel Transaction /Person:Ethel/Person:Jane /Person:Max 25 25
Standards-based Persistence > JDO or JPA (your choice) Established apis and existing tooling Easier porting Mappable (mostly) to the datastore Soft schemas > DataNucleus App Engine plugin > Why not a JDBC driver instead? 26 26
Transparent Entity Group Management > Entity Group layout is important Write throughput Atomicity of updates > Ownership implies co-location within Entity Group @Entity class Person { //... @OneToMany List<Pet> pets; } Kind Pet Entity Group /Person:Ethel Key /Person:Ethel/Pet:Sam 27 27
Demo! 28 28
Demo - Login 29 29
Demo - Question 30 30
Demo - Question Result 31 31
Demo - Scoreboard 32 32
Demo - Code! 33 33
http://java-demo.appspot.com 34 34
Toby Reyelts, Max Ross, Don Schwarz tobyr@google.com maxr@google.com schwardo@google.com http://code.google.com/appengine Google Group: google-appengine-java 35