Google App Engine Chien-Chung Shen [email protected].

19
Google App Engine Chien-Chung Shen [email protected]

Transcript of Google App Engine Chien-Chung Shen [email protected].

Page 1: Google App Engine Chien-Chung Shen cshen@udel.edu.

Google App Engine

Chien-Chung [email protected]

Page 2: Google App Engine Chien-Chung Shen cshen@udel.edu.

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

Page 3: Google App Engine Chien-Chung Shen cshen@udel.edu.

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

email using Google Accounts– a fully featured local development environment

that simulates Google App Engine on your computer

Page 4: Google App Engine Chien-Chung Shen cshen@udel.edu.

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)

Page 5: Google App Engine Chien-Chung Shen cshen@udel.edu.

Google App Engine Architecture

Page 6: Google App Engine Chien-Chung Shen cshen@udel.edu.

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

Page 7: Google App Engine Chien-Chung Shen cshen@udel.edu.

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." 

Page 8: Google App Engine Chien-Chung Shen cshen@udel.edu.

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

Page 9: Google App Engine Chien-Chung Shen cshen@udel.edu.

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

Page 10: Google App Engine Chien-Chung Shen cshen@udel.edu.

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 startof line indicatesend of header lines

GET /index.html HTTP/1.1\r\nHost: www-net.cs.umass.edu\r\nUser-Agent: Firefox/3.6.10\r\nAccept: text/html,application/xhtml+xml\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7\r\nKeep-Alive: 115\r\nConnection: keep-alive\r\n\r\n

carriage return character

line-feed character

Page 11: Google App Engine Chien-Chung Shen cshen@udel.edu.

HTTP request message: general format

requestline

headerlines

body

method sp sp cr lfversionURL

cr lfvalueheader field name

cr lfvalueheader field name

~~ ~~

cr lf

entity body~~ ~~

Page 12: Google App Engine Chien-Chung Shen cshen@udel.edu.

Application Layer 2-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: www.somesite.com/animalsearch?monkeys&banana

Page 13: Google App Engine Chien-Chung Shen cshen@udel.edu.

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

Page 14: Google App Engine Chien-Chung Shen cshen@udel.edu.

HTTP response message

status line(protocolstatus codestatus phrase)

header lines

data, e.g., requestedHTML file

HTTP/1.1 200 OK\r\nDate: Sun, 26 Sep 2010 20:09:20 GMT\r\nServer: Apache/2.0.52 (CentOS)\r\nLast-Modified: Tue, 30 Oct 2007 17:00:02

GMT\r\nETag: "17dc6-a5c-bf716880"\r\nAccept-Ranges: bytes\r\nContent-Length: 2652\r\nKeep-Alive: timeout=10, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html; charset=ISO-8859-1\

r\n\r\ndata data data data data ...

Right click on a page to view page source!!!

Page 15: Google App Engine Chien-Chung Shen cshen@udel.edu.

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:

Page 16: Google App Engine Chien-Chung Shen cshen@udel.edu.

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 80

2. type in a GET HTTP request:

GET /~ross/ HTTP/1.1Host: cis.poly.edu

by typing this in (hit carriagereturn twice), you sendthis minimal (but complete) GET request to HTTP server

3. look at response message sent by HTTP server!

Redirection: http://www.nyu.edu/projects/keithwross/

Page 17: Google App Engine Chien-Chung Shen cshen@udel.edu.

App Engine Request Handling Architecture

Page 18: Google App Engine Chien-Chung Shen cshen@udel.edu.

HTTP Location

• http://en.wikipedia.org/wiki/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

Page 19: Google App Engine Chien-Chung Shen cshen@udel.edu.

Demos

In go_appengine/demos• counter• delay• guestbook• helloworld• logviewer• mandelbrot• moustachio

– http://blog.golang.org/go-at-google-io-2011-videos