Google App Engine
Now Serving Java
Chris Schalk
June 29, 2009
Goals
•  Help you understand...
    –  what App Engine is.
    –  what App Engine is not.
    –  where App Engine preserves programming models.
    –  where App Engine changes programming models.
•  Demonstrate that App Engine really is fast and free to get
    started.




2
Overview
•  Google App Engine
•  Java on App Engine
•  The App Engine Datastore
•  Demo
•  Questions




3
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
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




5
App Engine Architecture



                                       Incoming Requests



                        App Engine        App Engine                App Engine
                         Front End         Front End                 Front End
     Load
    Balancer

                         AppServer        AppServer                 AppServer



                                                       Other Google
        AppServer                                      Infrastructure

                     API Layer                         - Bigtable

                                                       - Google Accounts

                                                       - Memcache
               App     App       App
                                                       - Image manipulation


6
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




7
Java Support
•  Servlets
•  Software services
•  Sandboxing
•  DevAppServer
•  Deployment
•  Tooling




8
Demo!
Java App Engine Basics
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




10
Software Services




     Authentication    Servlet API     Google Accounts

       Datastore        JPA, JDO           Bigtable

       Caching         javax.cache       memcacheg

        E-mail          javax.mail      Gmail gateway

       URLFetch       URLConnection   Caching HTTP proxy



11
Sandboxing
•  What do we do?
     –  Restrict JVM permissions
     –  WhiteList classes
•  Why is it necessary?
     –  Clustering - JVMs come and go
     –  Protect applications from one another




12
Sandboxing Restrictions




              Threads
               Async API (coming soon)

     Direct network connections
         URLConnection


      Direct file system writes
    Memory, memcache, datastore


                                            Images API
               Java2D
                                        Software rendering


            Native code
                Pure Java libraries


13
Flexible Sandboxing
•  JVM Permissions often too coarse
•  Reflection
     –  Access private fields, call private methods
•  Class Loading
     –  Custom Class Loaders
     –  Dynamic bytecode
•  Alternate JVM languages




14
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




15
Deployment
•  Your app lives at
     –  <app_id>.appspot.com, or
     –  Custom domain with Google Apps for your Domain
•  Command line and IDE tools
•  Application
•  Datastore Indexes
•  Cron Jobs




16
Quotas and Billing




         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


                      2000/day to users
      Emails sent                         $0.0001/email
                     5000/day to admins

17
Tooling
•  SDK Tools API
     –  Command-line tools, Ant, and IDE plugins
•  Provides
     –  Deployment
     –  DevAppServer
     –  WhiteList for compile-time checks
     –  XML validation
•  Google Eclipse Plugin




18
The Datastore Is...
•  Distributed
•  Scalable
•  Transactional
•  Natively Partitioned
•  Hierarchical
•  Schema-less
•  Based on Bigtable




19
The Datastore Is Not...
•  A relational database


•  A SQL engine


•  Just Bigtable




20
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




21
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)




22
Interesting Datastore Modeling Features
       •    Ancestor
       •    Multi-value properties
       •    Variable properties
       •    Heterogenous property types



Kind            Person            Kind           Person

Entity Group    /Person:Ethel
                                  Entity Group   /Person:Ethel
Key             /Person:Ethel

Age             Int64: 30
                                  Key            /Person:Ethel/Person:Jane
Hobbies         String: Tennis

                                  Age            Double: 3.5

 23

                                  Pets           Key:/Turtle:Sam Key:/Dog:Ernie
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



24
Datastore Queries
•  Every query must be supported by an index
     –  Built-in or user-defined
•  Filters
     –  Equality, inequality, intersection, ancestor
     –  Union, IN not supported (yet)
     –  Joins not supported (unlikely, but never say never)
•  Sorting




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
Transparent Entity Group Management
•  Entity Group layout is important
     –  Write throughput
     –  Atomicity of updates
•  Ownership implies co-location within Entity Group



                                      Kind
           Pet

                                      Entity Group
   /Person:Ethel


                                      Key
            /Person:Ethel/Pet:Sam




27
Demo!
Building Apps with Java App Engine
Coming Soon
•  Task queues
•  Full text search
•  Incoming email
•  XMPP
•  Large file storage and retrieval
•  Datastore export tools




29
Q&A
Google Developer Days Brazil 2009 -  Java Appengine

Google Developer Days Brazil 2009 - Java Appengine

  • 1.
    Google App Engine NowServing Java Chris Schalk June 29, 2009
  • 2.
    Goals •  Help youunderstand... –  what App Engine is. –  what App Engine is not. –  where App Engine preserves programming models. –  where App Engine changes programming models. •  Demonstrate that App Engine really is fast and free to get started. 2
  • 3.
    Overview •  Google AppEngine •  Java on App Engine •  The App Engine Datastore •  Demo •  Questions 3
  • 4.
    What Is GoogleApp 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
  • 5.
    Key Features •  Noneed 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 5
  • 6.
    App Engine Architecture Incoming Requests App Engine App Engine App Engine Front End Front End Front End Load Balancer AppServer AppServer AppServer Other Google AppServer Infrastructure API Layer - Bigtable - Google Accounts - Memcache App App App - Image manipulation 6
  • 7.
    When To UseGoogle 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 7
  • 8.
    Java Support •  Servlets • Software services •  Sandboxing •  DevAppServer •  Deployment •  Tooling 8
  • 9.
  • 10.
    Servlet API •  FullServlet 2.5 Container –  HTTP Session –  JSP •  Uses Jetty and Jasper –  Powered by Google’s HTTP stack –  No Jetty-specific features –  Subject to change 10
  • 11.
    Software Services Authentication Servlet API Google Accounts Datastore JPA, JDO Bigtable Caching javax.cache memcacheg E-mail javax.mail Gmail gateway URLFetch URLConnection Caching HTTP proxy 11
  • 12.
    Sandboxing •  What dowe do? –  Restrict JVM permissions –  WhiteList classes •  Why is it necessary? –  Clustering - JVMs come and go –  Protect applications from one another 12
  • 13.
    Sandboxing Restrictions Threads Async API (coming soon) Direct network connections URLConnection Direct file system writes Memory, memcache, datastore Images API Java2D Software rendering Native code Pure Java libraries 13
  • 14.
    Flexible Sandboxing •  JVMPermissions often too coarse •  Reflection –  Access private fields, call private methods •  Class Loading –  Custom Class Loaders –  Dynamic bytecode •  Alternate JVM languages 14
  • 15.
    DevAppServer •  Emulates theproduction environment •  Customized Jetty server •  Local implementation of services –  LRU memcache –  Disk-backed datastore –  HttpClient-backed URLFetch •  Some sandbox restrictions difficult to emulate 15
  • 16.
    Deployment •  Your applives at –  <app_id>.appspot.com, or –  Custom domain with Google Apps for your Domain •  Command line and IDE tools •  Application •  Datastore Indexes •  Cron Jobs 16
  • 17.
    Quotas and Billing 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 2000/day to users Emails sent $0.0001/email 5000/day to admins 17
  • 18.
    Tooling •  SDK ToolsAPI –  Command-line tools, Ant, and IDE plugins •  Provides –  Deployment –  DevAppServer –  WhiteList for compile-time checks –  XML validation •  Google Eclipse Plugin 18
  • 19.
    The Datastore Is... • Distributed •  Scalable •  Transactional •  Natively Partitioned •  Hierarchical •  Schema-less •  Based on Bigtable 19
  • 20.
    The Datastore IsNot... •  A relational database •  A SQL engine •  Just Bigtable 20
  • 21.
    Simplifying Storage •  Simplifydevelopment of apps •  Simplify management of apps •  App Engine services build on Google’s strengths •  Scale always matters –  Request volume –  Data volume 21
  • 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) 22
  • 23.
    Interesting Datastore ModelingFeatures •  Ancestor •  Multi-value properties •  Variable properties •  Heterogenous property types Kind Person Kind Person Entity Group /Person:Ethel Entity Group /Person:Ethel Key /Person:Ethel Age Int64: 30 Key /Person:Ethel/Person:Jane Hobbies String: Tennis Age Double: 3.5 23 Pets Key:/Turtle:Sam Key:/Dog:Ernie
  • 24.
    Datastore Transactions •  Transactionsapply 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 24
  • 25.
    Datastore Queries •  Everyquery must be supported by an index –  Built-in or user-defined •  Filters –  Equality, inequality, intersection, ancestor –  Union, IN not supported (yet) –  Joins not supported (unlikely, but never say never) •  Sorting 25
  • 26.
    Standards-based Persistence •  JDOor 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
  • 27.
    Transparent Entity GroupManagement •  Entity Group layout is important –  Write throughput –  Atomicity of updates •  Ownership implies co-location within Entity Group Kind Pet Entity Group /Person:Ethel Key /Person:Ethel/Pet:Sam 27
  • 28.
    Demo! Building Apps withJava App Engine
  • 29.
    Coming Soon •  Taskqueues •  Full text search •  Incoming email •  XMPP •  Large file storage and retrieval •  Datastore export tools 29
  • 30.