google appengine (gae/j) - introduction and overview from a java guy

26
Dr. Max Völkel, Calpano 1 You know Java, but what is AppEngine? In this session Max will walk you from a brief introducAon of Servlets to an overview of the Google AppEngine. We learn about the basics such as the data store – which is quite different from SQL , applicaAon versions, backends, scheduler, instances and logging. Services such as mail, url fetch, task queue are also explained. Since we use GAE/J since 2010 in Calpano we also talk about costs and experience in pracAce.

Post on 17-Oct-2014

963 views

Category:

Documents


2 download

DESCRIPTION

You know Java, but what is AppEngine? In this session Max will walk you from a brief introduction of Servlets to an overview of the Google AppEngine. We learn about the basics such as the data store – which is quite different from SQL -, application versions, back-ends, scheduler, instances and logging. Services such as mail, url fetch, task queue are also explained. Since we use GAE/J since 2010 in Calpano we also talk about costs and experience in practice.

TRANSCRIPT

Page 1: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Dr. Max Völkel, Calpano 1

You   know   Java,   but   what   is  AppEngine?   In   this   session  Max   will  walk  you  from  a  brief  introducAon  of  Servlets   to   an   overview   of   the  Google   AppEngine.   We   learn   about  the   basics   such   as   the   data   store   –  which   is   quite   different   from   SQL   -­‐,  applicaAon   versions,   back-­‐ends,  scheduler,   instances   and   logging.  Services   such  as  mail,   url   fetch,   task  queue   are   also   explained.   Since   we  use  GAE/J   since  2010   in  Calpano  we  also  talk  about  costs  and  experience  in  pracAce.    

Page 2: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Poll §  Language? §  Java? §  AppEngine? §  Servlets?

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 2

Page 3: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Do you know Servlets? §  HttpServlet

•  void doGet( HttpServletRequest req, "HttpServletResponse res);"

•  void doPost(…)"§  HttpServletRequest

•  get Header(…), get InputStream(...)"§  HttpServletResponse

•  set Header(…), getOutputStream(...)" See: http://java.sun.com/products/servlet/, AppEngine supports version 2.5"

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 3

Page 4: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

AppEngine is a Servlet Container

§  Servlet Container runs a Web Application Archive (WAR) •  Class files •  Static resources •  web.xml"

§  In AppEngine also: •  appengine-web.xml, queue.xml, cron.xml, backends.xml, indexes.xml, …

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 4

Page 5: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

AppEngine Architecture�Java/Python/Go

§  Running Code §  Storing Data

•  JVM •  Memcache •  Data store (Old vs. High

Replication) §  Connect to the outside world

•  Mail (Incoming, Outgoing) •  Urlfetch

§  Delay or schedule work •  Taskqueue •  Cron

§  More helper services •  Images •  Users

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 5

Servlet  Container    

JVM  

Data  Store  Memcache  Images  

HTTP,  Incoming  Mail,  Cron,  Taskqueue  

Urlfetch,  Outgoing  Mail,  Taskqueue  

Page 6: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Hello AppEngine §  Typical first test: •  Register, Verify mobile number via SMS •  Create new app “helloworld”

•  http://helloworld.appspot.com

§  Next step: •  Buy domain name •  Configure …

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 6

Page 7: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

1.  Appspot.com > Create App

2.  Go to “Apps for your Domain”�https://www.google.com/a/calpano.com

3.  Organization & Users > Create user�! Only those can send emails

4.  Domain Settings > �Domain names > �Add domain name or alias >

5.  Go to appspot.com and “Add Domain”

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 7

Page 8: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Application Versions §  http://{version}.{appid}.appspot.com"§  http://{appid].appspot.com �à main version (Selected in Dashboard)

§  All versions •  Share the same datastore, memcache (!) •  Different logs, stats, instances

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 8

Page 9: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Running Code §  Java 6 VM (experimental Java 7) §  No Files (only read the ones you put in your .war) §  Explicit whitelist which Java classes are allowed (many!)

•  https://developers.google.com/appengine/docs/java/jrewhitelist

§  F1: 8 cent/hour •  128MB memory (!), •  600MHz CPU

§  F2 = F1 * 2; F4 = F1 * 4 §  ! Servlet response max. time is 60 seconds

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 9

Page 10: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Storing Data §  JVM •  Great when “always on”

§  Memcache •  Really just a cache

§  Data store •  Old: Master-Slave (2 data centers) •  High Replication (3 data centers)

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 10

Page 11: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Connect to the outside world §  Mail •  Incoming

•  Send as a servlet request •  Outgoing

•  Via Java Mail API, only some headers used •  ! Bounce processing

•  http://code.google.com/p/googleappengine/issues/detail?id=1800

§  Urlfetch •  ! Calling Twitter API etc.

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 11

Page 12: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Delay or schedule work §  Taskqueue Queue queue = QueueFactory.getDefaultQueue();!queue.add(TaskOptions.Builder.withDefaults()!.payload(task));!

•  Task is a DeferredTask (has a run() method) •  Very quick to enqueue task •  Task queue service fires requests as

HttpRequests at defined rates, unwraps task, runs it

•  Max runtime: 10 minutes §  Cron •  Scheduled GET-requests at defined urls

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 12

Page 13: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

More helper services §  Images •  Looks like a subset of ImageMagick

§  Users •  Log in via Google Account

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 13

Page 14: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Where is a request going? Typical setup §  DNS lookup: CNAME or A-record to Google §  GAE scheduler: •  Request queue for your app •  Boot new instance? Takes ca. 10-30 seconds.

§  On instance: •  Run WAR, •  Run servlet

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 14

Page 15: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Instances

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 15

Page 16: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Time is Money. What time? §  Free vs. Payment enabled §  Quotas •  Usage – Free = Billable à Pay •  Resource quota à Fair use limit à Error page

§  Data store •  See also

http://blog.xam.de/2011/11/analysis-of-datastore-operation-cost.html

§  Instance hours •  Usage (code time * complexity + 15 min) •  What???

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 16

Page 17: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Real time vs. API time

§  CPU-intensive code is more expensive •  Is magically speed-up by AppEngine

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 17

Page 18: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

The Scheduler Appspot > App Settings > Performance

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 18

Page 19: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Appstats

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 19

Page 20: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

More stuff §  Backends •  Requests run for hours (or even days?)

§  Logging •  Java.util.logging runs fine

§  Blobstore §  Channel ~ like websockets §  XMPP §  Remote API: •  Call services remotely

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 20

Page 21: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Practical Tips on Datastore §  Don’t use JDO abstraction •  Leaky abstraction anyway

§  Low-level API quite easy •  Objectify (open source) makes using it nice •  Xydra.org adds versioning/synchronisation

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 21

Page 22: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Real-World Experiences §  Xydra §  Calpano.com §  SonicMetrics.com

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 22

Servlet  Container    

JVM  

Data  Store  Memcache  Images  

HTTP,  Incoming  Mail,  Cron,  Taskqueue  

Urlfetch,  Outgoing  Mail,  Taskqueue  

Page 23: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

When to use AppEngine? §  Best: Spikes in demand §  OK: Outsource server management

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 23

Page 24: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Where to learn more? §  Next talk from Florian Krupicka on

Continuous Integration with AppEngine and Maven

§  Google webseits – Docu, JavaDocs, Articles, §  Stackoverflow – Googles official developer

support moved there §  Books •  Programming Google AppEngine – was OK when

it came out, but now too outdated §  Book a workshop from Calpano Consulting J

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 24

Page 25: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Dr. Max Völkel

25

Servlet  Container    

JVM  

Data  Store  Memcache  Images  

HTTP,  Incoming  Mail,  Cron,  Taskqueue  

Urlfetch,  Outgoing  Mail,  Taskqueue  

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com

Page 26: Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy

Contact Information §  Dr. Max Völkel §  [email protected] §  +49 171 8359678

§  www.Calpano.com

GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com 26