google app engine go - meetupfiles.meetup.com/18311722/gae go meetup lyon.pdf · set of servers...

39
Fred Janon [email protected] what, why & how Google App Engine Go © ajendo 2015 1

Upload: others

Post on 28-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Fred Janon [email protected]

what, why & how

Google App Engine Go

© ajendo 2015 1

set of servers running independently in parallel behind load balancersset of highly scalable services: data storage, email , task queue, image operations, memory cache and moremanaged by Google system reliability engineers (SRE)https://www.google.com/about/careers/teams/engineering/systems/

GAE

© ajendo 2015 2

set of servers running independently in parallel behind load balancers (same as GAE)no restrictionsno GAE services (still can access some services via REST)like AWSalso managed by Google system reliability engineers (SRE)https://cloud.google.com/compute/docs/

Compute Engine

© ajendo 2015 3

Run Docker containers on Google Cloud Platform, powered by Kubernetes.Container Engine takes care of provisioning and maintaining the underlying virtual machine cluster, scaling your application, and operational logistics like logging, monitoring, and health management.

Container Engine (Alpha)

© ajendo 2015 4

GAE-Compute Engine Architecture

source: https://cloud.google.com/solutions/architecture/webapp© ajendo 2015 5

Compute Engine Architecture

source: https://cloud.google.com/solutions/architecture/highperformancecomputing© ajendo 2015 6

Mixed GAE - Compute Engine Architecture

source: https://cloud.google.com/solutions/architecture/realtimebidding© ajendo 2015 7

GAE or Compute Engine?

pick GAE if: you need a web serveryou need the GAE servicesyou don’t mind the restrictionsyou don’t want to manage at all any serverdev to deploy time extremely short

© ajendo 2015 8

GAE or Compute Engine?

pick Compute Engine if:you don’t need a web server, but a compute serveryou don’t need the GAE servicesyou need to access the file system or other

check also the GAE managed VMs (between GAE & Compute Engine)

https://cloud.google.com/appengine/docs/go/managed-vms/© ajendo 2015 9

Cons:GAE restrictions: java classes, access to file system, running time

Pros:fully managedinfinitely scalable (if done according to the rules)

check https://cloud.google.com/solutions/architecture/

GAE vs. Compute Engine

© ajendo 2015 10

Pricing

always a free tieruse calculators (if you can)https://cloud.google.com/appengine/#pricing-calchttps://cloud.google.com/products/calculator/

as of March 2015:GAE: free quota per app per day 28 instance hoursNew to Google Cloud Platform? We offer $300 in credit to spend on all Cloud Platform products for your first 60 days https://cloud.google.com/pricing/

© ajendo 2015 11

More solutions

pre-packaged solutions:MongoDB, Hadoop, MEAN...https://cloud.google.com/solutions/

© ajendo 2015 12

GAE Go vs Java

from Grails-Groovy on AWS 2005-2011 (no SQL on GAE)to GAE Java 2012-2013 (Google SQL)and finally GAE Go 2014 (Go SDK)

a lot less code with Go, lighter, faster, stable-> should save time and $$$

© ajendo 2015 13

GAE Go vs Java: Java

pros:stablerich ecosystemdocumentation & helptypedmore services than Go:https://cloud.google.com/appengine/docs/java/endpoints/

https://cloud.google.com/appengine/docs/java/sms/twilio

cons:VMs (launch could be slower)

no lambdasverbose (too much code)typed

© ajendo 2015 14

GAE Go vs Java: Gopros:APIs different from Javanow a rich ecosystemhelptyped, function pointersa LOT less codefaaaaaaaast

cons:APIs different from Javabeta? very stable

© ajendo 2015 15

GAE Go: web requests

App Engine specific headers:X-AppEngine-CountryX-AppEngine-RegionX-AppEngine-CityX-AppEngine-CityLatLonghttps://cloud.google.com/appengine/docs/go/requests

© ajendo 2015 16

GAE Go

install SDKdevelopdeploy… enjoy $$$GAE features supported by languagehttps://cloud.google.com/appengine/features/

© ajendo 2015 17

GAE Go

install SDK: GAE SDK or Cloud SDKhttps://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Gohttps://cloud.google.com/sdk/

developSublime Textdeploy… enjoy $$$

© ajendo 2015 18

GAE Go IDEsGoWorks Free, no update since 2013-01?http://tunnelvisionlabs.com/products/demo/goworks

Zeus Free for 45 days (out of Sydney?)http://www.zeusedit.com/go.htmlGAE auto-complete http://www.zeusedit.com/phpBB3/viewtopic.php?f=5&t=7458

GoLangIDE (GAE?)https://code.google.com/p/golangide/

Eclipse plugin goclipse (GAE?)https://code.google.com/p/goclipse/

© ajendo 2015 19

GAE Go IDEs

Lighttable Go Pluginhttps://github.com/toqueteos/LightTable-Gohttp://www.chris-granger.com/2013/01/24/the-ide-as-data/

© ajendo 2015 21

GAE Go SDK

install SDKcreate a folder/dir with the simplest web apprun it locallycreate an account & a project on GAEdeploy your app on GAEcheck it on the web

© ajendo 2015 22

GAE Go SDK (Win)

download Python 2.7.x, required with GOSDKadd GO SDK path to PATH env variablecommand line ">goapp" to check PATH

Check Go workspaceshttp://blog.golang.org/the-app-engine-sdk-and-workspaces-gopath

© ajendo 2015 23

GAE Go

GO GAE projecthttps://developers.google.com/appengine/docs/go/gettingstarted/helloworldhttps://cloud.google.com/appengine/docs/go/gettingstarted/introduction

goapp serve appgogaegoapp deployCAUTION: don’t forget to enable the services your project uses in the project dashboard

© ajendo 2015 24

GAE Go: hello.gopackage helloimport ( "fmt" "net/http")func init() { // router http.HandleFunc("/", handler)}func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, world!")}

© ajendo 2015 25

GAE Go: app.yaml - config file 1/3

application: helloworldversion: 1runtime: goapi_version: go1

handlers:- url: /.* script: _go_apphttps://cloud.google.com/appengine/docs/go/config/appconfig

© ajendo 2015 26

GAE Go: app.yaml - config file 2/3

application: myappversion: alpha-001runtime: goapi_version: go1

© ajendo 2015 27

GAE Go: app.yaml - config file 3/3

handlers:- url: /stylesheets static_dir: stylesheets- url: /(.*\.(gif|png|jpg))$ static_files: static/\1 upload: static/.*\.(gif|png|jpg)$- url: /.* script: _go_app

© ajendo 2015 28

GAE Go: debugging with loggingto use logging in Go GAE app, works:import (

"appengine" "fmt" "net/http")func init() { http.HandleFunc("/", home)}

© ajendo 2015 29

GAE Go: debugging with logging

func home(wrt http.ResponseWriter, req *http.Request) {var ctx appengine.Contextctx = appengine.NewContext(req)ctx.Infof("home") // <- loggingfmt.Fprint(wrt, "home sweet home...")

}

© ajendo 2015 30

GAE Go: debugging with logging

appengine context.Debugf(format string, args ...interface{})Infof(format string, args ...interface{})Warningf(format string, args ...interface{})Errorf(format string, args ...interface{})Criticalf(format string, args ...interface{})

© ajendo 2015 31

GAE Go: deploy

deploy go project: app id in app.yamllogin with email + pass didn't work, probably because of 2FA on gmailwhen goapp deploy, a message comes up after the email/pass and suggests to use OAuth2:https://developers.google.com/appengine/docs/go/tools/uploadinganapp#Go_Password-less_login_with_OAuth2Must do that and deployment starts and succeeds after that.goapp deploy -oauth © ajendo 2015 32

GAE Go: GAE Go errortype error interface { Error() string}The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no errorcreating custom error:errors.New("ObjectProps has inconsistent sum")http://golang.org/pkg/errors/http://blog.golang.org/errors-are-values

© ajendo 2015 33

GAE Go: unit testingUnit Testing in GAE Gohttps://developers.google.com/appengine/docs/go/tools/localunittestinggoapp test ./demos/transactionto run only selected tests for GAE Gosee goapp help testflaggoapp test -run "TestSaveListFloat64"

© ajendo 2015 34

GAE Go: whole sequenceC:\Console2>cd \websetC:\webset>goapp servegoapp test -run "TestSomeGoodCode"http://localhost:8080goapp deploy -oauthhttps://console.developers.google.com/http://yourapphere.appspot.comhttp://yourapphere.appspot.com/ehttp://yourapphere.appspot.com/p © ajendo 2015 35

GAE Go: misc.

offline docs:https://sites.google.com/site/gdgdevkitpilotreadme/home/downloadsgo playground + share to save the codehttps://play.golang.org/go gae google grouphttps://groups.google.com/forum/#!forum/google-appengine-goGAE modules: mix languageshttps://cloud.google.com/appengine/docs/go/modules/

© ajendo 2015 36

GAE Go: misc.

caution when using external libraries: are they scalable?no view on the server content (split between static & dynamic)use & make packagestest, test & testonline debugging, not for go yetcheck SDK updates often

© ajendo 2015 37

GAE Go: fun

function pointersmemoizationdynamic structures in datastore with channels

© ajendo 2015 38

GAE Goinstall SDKdevelopdeploypay $… enjoy $$$$$$

BigQuery example in GAE Javahttps://bitbucket.org/fjanon/bigquery-example/

© ajendo 2015 39