google app engine: java technology in the cloud · google app engine: java technology in the cloud...

49
Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google 1 Thursday, 4 June 2009

Upload: others

Post on 28-May-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Google App Engine:Java TechnologyIn The Cloud

Toby Reyelts, Max Ross, Don SchwarzGoogle

1Thursday, 4 June 2009

Page 2: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Goals

> Google App Engine> Java on App Engine> The App Engine Datastore> Demo> Questions

2

2Thursday, 4 June 2009

Page 3: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

3Thursday, 4 June 2009

Page 4: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

4Thursday, 4 June 2009

Page 5: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

App Engine Architecture

5

Incoming Requests

5Thursday, 4 June 2009

Page 6: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

App Engine Architecture

5

Incoming Requests

App Engine Front End

App Engine Front End

App Engine Front End

5Thursday, 4 June 2009

Page 7: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

App Engine Architecture

5

AppServer AppServer AppServer

Incoming Requests

App Engine Front End

App Engine Front End

App Engine Front End

5Thursday, 4 June 2009

Page 8: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

App Engine Architecture

5

AppServer AppServer AppServer

Incoming Requests

App Engine Front End

App Engine Front End

App Engine Front End

Load Balancer

5Thursday, 4 June 2009

Page 9: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

App Engine Architecture

5

AppServer AppServer AppServer

Incoming Requests

App Engine Front End

App Engine Front End

App Engine Front End

Load Balancer

AppServer

API Layer

Other Google Infrastructure

- Bigtable

- Google Accounts

- Memcache

- Image manipulation

App App App

5Thursday, 4 June 2009

Page 10: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

6Thursday, 4 June 2009

Page 11: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

WebHooks (coming soon)

> Incoming email> XMPP> Google Wave> Task Queues

7

7Thursday, 4 June 2009

Page 12: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Java Support

> Servlets> Software services> Sandboxing> DevAppServer> Deployment> Tooling

8

8Thursday, 4 June 2009

Page 13: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

9Thursday, 4 June 2009

Page 14: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Software Services

10

Service Java Standard Google InfrastructureAuthentication Servlet API Google Accounts

Datastore JPA, JDO Bigtable

Caching javax.cache memcacheg

E-mail javax.mail Gmail gateway

URLFetch URLConnection Caching HTTP proxy

10Thursday, 4 June 2009

Page 15: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

11Thursday, 4 June 2009

Page 16: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Sandboxing Restrictions

12

Restriction Alternative

Threads Async and Queue API (Soon!)

Direct network connections URLConnection

Direct file system writes Memory, memcache, datastore

Java2D Images APISoftware rendering

Native code Pure Java libraries

12Thursday, 4 June 2009

Page 17: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing

13

13Thursday, 4 June 2009

Page 18: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing

13

JVM Permissions often too coarse.

13Thursday, 4 June 2009

Page 19: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing

13

JVM Permissions often too coarse.They either provide a cramped sandbox.

13Thursday, 4 June 2009

Page 20: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing

13

JVM Permissions often too coarse.They either provide a cramped sandbox.

Or they hand over the nuclear launch codes.

13Thursday, 4 June 2009

Page 21: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing

13

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.

13Thursday, 4 June 2009

Page 22: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Reflection

14

14Thursday, 4 June 2009

Page 23: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Reflection

> Access private fields, call private methods• suppressAccessChecks• accessDeclaredMembers

14

14Thursday, 4 June 2009

Page 24: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Reflection

> Access private fields, call private methods• suppressAccessChecks• accessDeclaredMembers

14

Field f = String.class.getDeclaredField(“count”);f.setAccessible(true);

f.set(“Hello World”, 2);

Bad!

14Thursday, 4 June 2009

Page 25: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Reflection

> Access private fields, call private methods• suppressAccessChecks• accessDeclaredMembers

14

Field f = String.class.getDeclaredField(“count”);f.setAccessible(true);

f.set(“Hello World”, 2);

Field f = MyClass.class.getDeclaredField(“foo”);f.setAccessible(true);

f.set(myObj, aFoo);

Bad!

Good!

14Thursday, 4 June 2009

Page 26: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Class Loading

15

15Thursday, 4 June 2009

Page 27: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Class Loading

> Create user-controlled ClassLoaders• createClassLoader

15

15Thursday, 4 June 2009

Page 28: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Class Loading

> Create user-controlled ClassLoaders• createClassLoader

15

Bad!ClassLoader myClassLoader = new URLClassLoader() {

public PermissionsCollection getPermissions(CodeSource cs) {

// return AllPermission;

}

};

15Thursday, 4 June 2009

Page 29: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Flexible Sandboxing - Class Loading

> Create user-controlled ClassLoaders• createClassLoader

15

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

}

};

15Thursday, 4 June 2009

Page 30: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

16Thursday, 4 June 2009

Page 31: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

17Thursday, 4 June 2009

Page 32: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

18Thursday, 4 June 2009

Page 33: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Quotas and Billing

19

Resource Provided Free Additional CostCPU 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 users5000/day to admins $0.0001/email

19Thursday, 4 June 2009

Page 34: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Tooling

> SDK Tools API• Command-line tools, Ant, and IDE plugins

> Provides• Deployment• DevAppServer• WhiteList• XML validation

> Google Eclipse Plugin, Intellij Plugin

20

20Thursday, 4 June 2009

Page 35: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

The Datastore Is...

> Transactional> Natively Partitioned> Hierarchical> Schema-less> Based on Bigtable> Not a relational db> Not a SQL engine

21

Wow. That isone big table.

21Thursday, 4 June 2009

Page 36: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

22Thursday, 4 June 2009

Page 37: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

23Thursday, 4 June 2009

Page 38: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Interesting Datastore Modeling Features

> Ancestor> Multi-value properties> Variable properties> Heterogenous property types

24

Kind PersonEntity Group /Person:EthelKey /Person:EthelAge Int64: 30Hobbies String: Tennis

Kind PersonEntity Group /Person:EthelKey /Person:Ethel/Person:JaneAge Double: 3.5Pets Key:/Turtle:Sam Key:/Dog:Ernie

24Thursday, 4 June 2009

Page 39: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Datastore Transactions

> Transactions apply to a single Entity Group• Global transactions are feasible

> get(), put(), delete() are transactional> Queries are not transactional (yet)

25

/Person:Ethel/Person:Jane

/Person:Ethel

/Person:Max

Transaction

25Thursday, 4 June 2009

Page 40: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

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

26Thursday, 4 June 2009

Page 41: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

@Entity

class Person {

// ...

@OneToMany

List<Pet> pets;

}

Transparent Entity Group Management

> Entity Group layout is important• Write throughput• Atomicity of updates

> Ownership implies co-location within Entity Group

27

Kind PetEntity Group /Person:EthelKey /Person:Ethel/Pet:Sam

27Thursday, 4 June 2009

Page 42: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

28

Demo!

28Thursday, 4 June 2009

Page 43: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Demo - Login

29

29Thursday, 4 June 2009

Page 44: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Demo - Question

30

30Thursday, 4 June 2009

Page 45: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Demo - Question Result

31

31Thursday, 4 June 2009

Page 46: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

Demo - Scoreboard

32

32Thursday, 4 June 2009

Page 47: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

33

Demo - Code!

33Thursday, 4 June 2009

Page 48: Google App Engine: Java Technology In The Cloud · Google App Engine: Java Technology In The Cloud Toby Reyelts, Max Ross, Don Schwarz Google Thursday, 4 June 2009 1. Goals ... •

34

http://java-demo.appspot.com

34Thursday, 4 June 2009