2011 june-kuala-lumpur-gtug-hackathon

35
Ikai Lan Kuala Lumpur, GTUG Hackathon Twitter: @ikai June 18, 2011 Google App Engine Saturday, June 18, 2011

Upload: ikailan

Post on 08-May-2015

1.590 views

Category:

Documents


0 download

DESCRIPTION

Slides for my presentation at the GTUG hackathon in Kuala Lum

TRANSCRIPT

Page 1: 2011 june-kuala-lumpur-gtug-hackathon

Ikai LanKuala Lumpur, GTUG Hackathon

Twitter: @ikaiJune 18, 2011

Google App Engine

Saturday, June 18, 2011

Page 2: 2011 june-kuala-lumpur-gtug-hackathon

About the speaker

• Developer Relations at Google based out of San Francisco, CA

• Primarily work in Java and Python nowadays; lots of experience with Ruby, JavaScript, PHP <5.3

• Focus: Cloud products

• Twitter: @ikai

Saturday, June 18, 2011

Page 3: 2011 june-kuala-lumpur-gtug-hackathon

Agenda

• What is Google App Engine?

• Various features of GAE

• How to get started

• Introduction to Go

• Important tools + some tips

Saturday, June 18, 2011

Page 4: 2011 june-kuala-lumpur-gtug-hackathon

Infrastructure

Platform

Software

Source: Gartner AADI Summit Dec 2009

Saturday, June 18, 2011

Page 5: 2011 june-kuala-lumpur-gtug-hackathon

Infrastructure

Platform

Software

Source: Gartner AADI Summit Dec 2009

Saturday, June 18, 2011

Page 6: 2011 june-kuala-lumpur-gtug-hackathon

Infrastructure

Platform

Software

Source: Gartner AADI Summit Dec 2009

Saturday, June 18, 2011

Page 7: 2011 june-kuala-lumpur-gtug-hackathon

Infrastructure

Platform

Software

Source: Gartner AADI Summit Dec 2009

Saturday, June 18, 2011

Page 8: 2011 june-kuala-lumpur-gtug-hackathon

• Easy to build

• Easy to manage

• Easy to scale

Saturday, June 18, 2011

Page 9: 2011 june-kuala-lumpur-gtug-hackathon

“We wear pagers soyou don’t have to”

Saturday, June 18, 2011

Page 10: 2011 june-kuala-lumpur-gtug-hackathon

Saturday, June 18, 2011

Page 11: 2011 june-kuala-lumpur-gtug-hackathon

>130K Apps

>90K Developers

>700M daily pageviews

Saturday, June 18, 2011

Page 12: 2011 june-kuala-lumpur-gtug-hackathon

SDK & “The Cloud”

Hardware

Networking

Operating system

Application runtime

Java, Python, Go

Static file serving

20

Saturday, June 18, 2011

Page 13: 2011 june-kuala-lumpur-gtug-hackathon

• Write code locally

• Test, push to Google Servers

• Administer via a web interface - http://appengine.google.com

Development Cycle

Saturday, June 18, 2011

Page 14: 2011 june-kuala-lumpur-gtug-hackathon

Admin Console

Saturday, June 18, 2011

Page 15: 2011 june-kuala-lumpur-gtug-hackathon

Duke, the Java mascotCopyright © Sun Microsystems Inc., all rights reserved.Go Gopher

Saturday, June 18, 2011

Page 16: 2011 june-kuala-lumpur-gtug-hackathon

• Java

• Scala

• JRuby (Ruby)

• Groovy

• Quercus (PHP)

• Rhino (JavaScript)

• Jython (Python)

• Clojure

Duke, the Java mascotCopyright © Sun Microsystems Inc., all rights reserved.

Extended Language support through JVM

Saturday, June 18, 2011

Page 17: 2011 june-kuala-lumpur-gtug-hackathon

BlobstoreImages

Mail XMPP Task Queue

Memcache Datastore URL Fetch

User Service

Core APIs

Saturday, June 18, 2011

Page 18: 2011 june-kuala-lumpur-gtug-hackathon

• Strongly consistent, multi-datastore, multi-data center serving solution

• Write once, have your data be available in a highly consistent manner

•No data loss, no datastore outages

High Replication

Saturday, June 18, 2011

Page 19: 2011 june-kuala-lumpur-gtug-hackathon

Other APIs

• High performance image serving

• App Engine Map Reduce

• Prospective Search API

• Pipeline API

• OAuth provider

Saturday, June 18, 2011

Page 20: 2011 june-kuala-lumpur-gtug-hackathon

Prospective Search

• Matches a high rate of incoming documents

• 100,000 matches a second

• Think: How might we build something like Google Alerts?

• http://code.google.com/appengine/docs/python/prospectivesearch/

Saturday, June 18, 2011

Page 21: 2011 june-kuala-lumpur-gtug-hackathon

A basic Python app

• 2 files: app.yaml and main.py

• Easier to use when Python SDK is in your system path

• Start server with dev_appserver.py

• Deploy via appcfg.py

Saturday, June 18, 2011

Page 22: 2011 june-kuala-lumpur-gtug-hackathon

app.yaml

Saturday, June 18, 2011

Page 23: 2011 june-kuala-lumpur-gtug-hackathon

main.py

Saturday, June 18, 2011

Page 24: 2011 june-kuala-lumpur-gtug-hackathon

Getting started with Java

• Servlets API

• Google Plugin for Eclipse will generate a skeleton project: http://code.google.com/eclipse/beta/docs/download.html

Saturday, June 18, 2011

Page 25: 2011 june-kuala-lumpur-gtug-hackathon

Go: why I like it

• “The next version of C, brought to you by the guys who didn’t bring you C++”

• Modern, type safe compiled language (stdlib includes: json parsing, web server)

• Functions as first class objects

• Concurrency baked in via goroutines and channels

• Very fast compilation times

Saturday, June 18, 2011

Page 26: 2011 june-kuala-lumpur-gtug-hackathon

Flexible interfaces// This is an interface declarationtype myInterface interface { set(i int)}

// This is a Type declaration. Note that it is a type, not a classtype myType struct { i int }

// This is how we define a function where myType is a receiver// With an instance of myType we can call myType.set(123)func (p *myType) set(i int) { p.i = i }

// Because myType defines a function with the signature set(int i) method, // we can use it anywhere myInterface is accepted!func setToThousand(x myInterface) { myInterface.set(1000)}

Saturday, June 18, 2011

Page 27: 2011 june-kuala-lumpur-gtug-hackathon

First class functionspackage main import "fmt"

// Make a function that returns a new functionfunc makeAdd(increment int) (counter func(int) int) { return func(v int) int { return v + increment; } }

func main() { fmt.Printf("value of makeAdd(100)(1) is %v\n", makeAdd(100)(1)); fmt.Printf("value of makeAdd(200)(2) is %v\n", makeAdd(200)(2)); }

// Outputs:// value of makeAdd(100)(1) is 101// value of makeAdd(200)(2) is 202

Saturday, June 18, 2011

Page 28: 2011 june-kuala-lumpur-gtug-hackathon

Goroutines and Channels

package main import ( "fmt" "time")

func doLotsOfWork(until int, ch chan int) { c := 0 for i := 0; i < until; i++ { c += i time.Sleep(1000) } ch <- c }

func main() { ch := make(chan int) // First the work off into the background go doLotsOfWork(5, ch) // Do more work here while we wait for this process to complete // Block until doLotsOfWork sends data back on this channel i := <- ch fmt.Printf("Final value: %v\n", i)}

Saturday, June 18, 2011

Page 29: 2011 june-kuala-lumpur-gtug-hackathon

It runs on App Engine!

• Currently requires whitelisting

• Experimental status

• Goroutines allow for concurrency within request; concurrent requests coming

• Demo app: http://moustach-io.appspot.com/

• Source: https://code.google.com/p/appengine-go/source/browse/example/

Saturday, June 18, 2011

Page 30: 2011 june-kuala-lumpur-gtug-hackathon

Mustachio

Saturday, June 18, 2011

Page 31: 2011 june-kuala-lumpur-gtug-hackathon

General tips

• The datastore is built on top of BigTable. It is non-relational!

• Be aware of limits: 30 second requests, 10 minute tasks queues/cron jobs, whitelisted classes

• Python 2.5 compatible (but can use 2.6 or 2.7 locally)

Saturday, June 18, 2011

Page 33: 2011 june-kuala-lumpur-gtug-hackathon

Java tips

• Use low-level datastore API or third party API: http://code.google.com/p/objectify-appengine/

• Start with servlets API - will have to do some work to make your favorite framework work. Slim3 is a good GAE specific framework

Saturday, June 18, 2011

Page 34: 2011 june-kuala-lumpur-gtug-hackathon

Summary

• Hopefully people here are interested in hacking on App Engine

• Java, Python and Go

• Ask me if you have general questions, I will be around all weekend

Saturday, June 18, 2011

Page 35: 2011 june-kuala-lumpur-gtug-hackathon

Questions?

• Twitter: @ikai

• App Engine: http://code.google.com/appengine

Saturday, June 18, 2011