1
© 2010 VMware Inc. All rights reserved
Google AppEngine
Recommended Text:
Programming Google App Engine
Dan Sandersons O’Reilly
2
AppEngine
! Web application hosting environment ! Highly scalable ! Automatic scaling • AppEngine allocates resources to the application as needed
! Fault tolerant
3
Components
! Run time environment • Java
• Python • PHP
• Go
! Datastore • Object database
! Scalable services • URL Fetch
• Mail • Image manipulation
• Extensible Messaging and Presence Protocol (XMPP) • Task queue (asynchronous processing)
4
Runtime Environment
! Stateless • Springs into existence to handle a request
• May go away after request is over • Requests routed independently to some server in infrastructure
! Sandboxing • Read only access to local file system • Limits the amount of resources per request
• Memory and CPU time • Application that use a lot of CPU of memory are throttled
• No new thread creation
• No direct networking • No awareness of other applications running on the same host
2
5
Eclipse Google Plugin
! Create AppEngine projects ! Debug project locally ! Upload projects to AppEngine
6
Directory Structure
7
AppEngine Console
! https://appengine.google.com/
8
Application Configuration
! war/WEB-INF/appengine-web.xml
! AppEngine URL • http://[{version}.]{appname}.appspot.com/
• http://1.ece1779.appspot.com • http://ece1779.appspot.com
3
9
Logging
! AppEngine logs all requests • Data, time, client IP, URL, referring URL user-agent, HTTP status code
• CPU time, response size
! Applications can also log events
10
Logging
! Java log levels: FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE
! Logging level configured in war/WEB-INF/logging.properties .level = INFO ClassName.level = ERROR
! AppEngine log levels: debug, info, warning, error, critical finest, finer, fine, config -> debug severe -> error un caught exceptions -> critical
! Writes to stdout are logged at “info” level ! Writes to stderr are logged at “warning” level
11
Request Handling
! Requests are short: 30 sec max.
12
Static File Configuration
! Two kinds of files • Static: deployed on static servers
• Resource: deployed on application servers
! Default policy • Static: all files in WAR except contents of WEB-INF and JSPs
• Resources: all files in WAR
! Customize policy in war/WEB-INF/appengine-web.xml <resource-files>
<exclude path=“/images/**” /> <resource-files>
<static-files> <exclude path=“/**.xml” /> <include path=“sitemap.xml” expiration=“2d” />
</static-files>
4
13
Integration with Google Accounts
! Possible to use Google Accounts to handle user authentication ! Can detect whether the current user has signed in ! Redirect the user to the appropriate sign-in page to sign in ! App can access the user's email address ! Detect whether the current user is an administrator • Simplify implementation of admin-only areas of the app.
import com.google.appengine.api.users.User; import com.google.appengine.api.users.UserService; import com.google.appengine.api.users.UserServiceFactory;
UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); user.getEmail(); user.getUserId();
14
Storage
! AppEngine Datastore • a NoSQL schemaless object datastore, with a query engine and atomic
transactions.
! Google Cloud SQL • Managed relational database
• https://developers.google.com/cloud-sql/
! Google Cloud Storage • Scalable, highly available storage service for objects and files up to terabytes
• https://developers.google.com/storage/
15
Datastore
! Highly scalable ! Fault tolerant ! Distributed ! Resembles a object database ! Data stored as entities ! Entity consists of: • Kind
• Similar to a RDB table, immutable
• Key • Immutable
• Properties • Different entities of the same kind may store different properties • A property can store multiple values at once
16
Java Persistence API (JPA)
! Standard Java API for persisting Java objects ! Supported by AppEngine Datastore ! Annotations define entity kind, id and which properties to persist • By default JPA persists builtin Java types (e.g., String, Date) • @Basic persists a non-standard Java type property • @Transient marks property as non-persistent
5
17
Java Persistence API (JPA)
! J2EE standard ! Supported by Google Datastore ! Mappings • kinds -> classes
• entities -> objects • fields -> properties
! Data types supported by either • Primitive Java data type (e.g., String, Int) • Application-defined data type (e.g., Preferences)
18
EntityManagerFactory
! Object that interacts with the Datastore
19
Saving an Entity
20
Fetching/Deleting an Entity
6
21
Security Configuration
! Configured in war/WEB-INF/web.xml ! HTTPS
! User authorization with Google Accounts • <role-name> can be either * or admin
22
Frontend Performance
! Can configure in management console ! Administration->Application Settings->Performance • Frontend Instance Class
• Idle instances • # of idle instances kept in standby
• Pending latency • Latency before starting new instance to handle waiting requests
23
Backend Performance
! Special App Engine instances ! Have no request deadlines, higher memory and CPU limits ! Persistent state across requests ! Started automatically ! Can run continously for long periods ! Individually addressable • http://[instance].[backend_name].[your_app_id].appspot.com
24
Bankend Configuration
! war/WEB-INF/backends.xml
! Administer • AppEngine management console
• appcfg.sh command line tool (part of the Java SDK)
Top Related