Google App Engine Chien-Chung Shen
Google App Engine Overview What is Google App Engine? – runtime platform that provides web application hosting, data storage, and high-speed networking – infrastructure (datacenters) available at Google their servers + storage Why it is GREAT? – Does one thing well: running web apps App Engine handles HTTP(S) requests, nothing else – Simple app configuration – Everything is built to scale Automatic Scaling to Application Needs – Secure – pay for what you use
Google App Engine Features Google App Engine makes it easy to build an application that runs reliably, even under heavy load and with large amounts of data – dynamic web serving, with full support for common web technologies – persistent storage with queries, sorting and transactions – automatic scaling and load balancing – APIs for authenticating users and sending using Google Accounts – a fully featured local development environment that simulates Google App Engine on your computer
The Runtime Environment Java environment – Java 7 Virtual Machine (JVM) – Java Servlet standard interface for interacting with the application server Python Environment – Python 2.7 Go PHP Java or python? – Python: powerful python syntax, library, shorter code – Java: can use Java Data Objects (JDO) and Java Persistence API (JPA)
Google App Engine Architecture
The Sandbox Applications run in a secure environment that provides limited access to the underlying OS – Benefit? will NEVER affect other applications on the same server – Cannot spawn additional processes or threads – Cannot make arbitrary network connections – Only read its own code and resource files and cannot create or modify files Examples of the limitations of the secure sandbox – An application can only access other computers on the Internet through the provided URL fetch and services. Other computers can only connect to the application by making HTTP (or HTTPS) requests on the standard ports – Applications cannot write to the file system in any of the runtime environments
Datastore App Engine provides a distributed NoSQL data storage service that features a query engine and transactions – datastore is not like a traditional relational database Data objects have a set of properties Queries can retrieve entities of a given kind filtered and sorted by the values of the properties – datastore entities are "schemaless." The structure of data entities is provided by and enforced by your application code – datastore provides ACID (Atomicity, Consistency, Isolation, Durability) transactions using optimistic concurrency control – datastore implements transactions across its distributed network using "entity groups."
Google Accounts App Engine supports integrating an app with Google Accounts for user authentication – your application can allow a user to sign in with a Google account, and access the address and displayable name associated with the account – lets the user start using your application faster – no need to create a new account – can judge whether the current user is a registered administrator for the application, which make it easy to implement admin-only areas of your site
App Engine Services App Engine provides a variety of services that enable you to perform common operations when managing your application – URL Fetch – Mail – Memcache high performance in-memory key-value cache that is accessible by multiple instances of your application – Image Manipulation – Extensible Messaging and Presence Protocol (XMPP) for real-time communication such as instant messaging – Task Queues keep track of tasks to handle in the background
HTTP request message two types of HTTP messages: request, response HTTP request message: – ASCII (human-readable format) request line (GET, POST, HEAD commands ) header lines carriage return, line feed at start of line indicates end of header lines GET /index.html HTTP/1.1\r\n Host: www-net.cs.umass.edu\r\n User-Agent: Firefox/3.6.10\r\n Accept: text/html,application/xhtml+xml\r\n Accept-Language: en-us,en;q=0.5\r\n Accept-Encoding: gzip,deflate\r\n Accept-Charset: ISO ,utf-8;q=0.7\r\n Keep-Alive: 115\r\n Connection: keep-alive\r\n \r\n carriage return character line-feed character
HTTP request message: general format request line header lines body method sp cr lf version URL cr lf value header field name cr lf value header field name ~ ~ ~ ~ cr lf entity body ~ ~ ~ ~
Application Layer2-12 Uploading form input POST method: web page often includes form input input is uploaded to server in entity body URL method: uses GET method input is uploaded in URL field of request line:
Method types HTTP/1.0: GET POST HEAD – asks server to leave requested object out of response HTTP/1.1: GET, POST, HEAD PUT – uploads file in entity body to path specified in URL field DELETE – deletes file specified in the URL field
HTTP response message status line (protocol status code status phrase) header lines data, e.g., requested HTML file HTTP/ OK\r\n Date: Sun, 26 Sep :09:20 GMT\r\n Server: Apache/ (CentOS)\r\n Last-Modified: Tue, 30 Oct :00:02 GMT\r\n ETag: "17dc6-a5c-bf716880"\r\n Accept-Ranges: bytes\r\n Content-Length: 2652\r\n Keep-Alive: timeout=10, max=100\r\n Connection: Keep-Alive\r\n Content-Type: text/html; charset=ISO \r\n \r\n data data data data data... Right click on a page to view page source!!!
HTTP response status codes 200 OK – request succeeded, requested object later in this msg 301 Moved Permanently – requested object moved, new location specified later in this msg (Location:) 400 Bad Request – request msg not understood by server 404 Not Found – requested document not found on this server 505 HTTP Version Not Supported status code appears in 1st line in server-to-client response message. some sample codes :
Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: opens TCP connection to port 80 (default HTTP server port) at cis.poly.edu. anything typed in sent to port 80 at cis.poly.edu telnet cis.poly.edu type in a GET HTTP request: GET /~ross/ HTTP/1.1 Host: cis.poly.edu by typing this in (hit carriage return twice), you send this minimal (but complete) GET request to HTTP server 3. look at response message sent by HTTP server! Redirection:
App Engine Request Handling Architecture
HTTP Location HTTP Location header field is returned in responses from an HTTP server under two circumstances: – To ask a web browser to load a different web page (URL redirection) – To provide information about the location of a newly created resource
Demos In go_appengine/demos counter delay guestbook helloworld logviewer mandelbrot moustachio –