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.
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
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.
Dr. Max Völkel, Calpano
1
3. 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
4. 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
5. AppEngine Architecture
Java/Python/Go
§ Running Code
HTTP,
Incoming
Mail,
§ Storing Data
Cron,
Taskqueue
• JVM
• Memcache
• Data store (Old vs. High
Replication)
Servlet
Container
§ Connect to the outside world
• Mail (Incoming, Outgoing)
JVM
• Urlfetch
§ Delay or schedule work
• Taskqueue
Memcache
• Cron
Data
Store
Images
§ More helper services
• Images
Urlfetch,
Outgoing
Mail,
• Users
Taskqueue
GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com
5
6. 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
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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
16. 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
17. 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
18. The Scheduler
Appspot > App Settings > Performance
GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com
18
20. 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
21. 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
22. Real-World Experiences
§ Xydra
HTTP,
Incoming
Mail,
Cron,
Taskqueue
§ Calpano.com
§ SonicMetrics.com
Servlet
Container
JVM
Memcache
Data
Store
Images
Urlfetch,
Outgoing
Mail,
Taskqueue
GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com
22
23. When to use AppEngine?
§ Best: Spikes in demand
§ OK: Outsource server management
GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com
23
24. 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
25. HTTP,
Incoming
Mail,
Cron,
Taskqueue
Servlet
Container
JVM
Memcache
Data
Store
Images
Urlfetch,
Outgoing
Mail,
Taskqueue
Dr. Max Völkel
GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com
25
26. Contact Information
§ Dr. Max Völkel
§ Max.voelkel@calpano.com
§ +49 171 8359678
§ www.Calpano.com
GDG Karlsruhe DevFest 2012 | Dr. Max Völkel | Calpano.com
26