Google App Engine for Java
Luca Marrocco
Spring Framework Meeting 2009 - Cagliari
www.exmachina.ch
in <code> we trust
Agenda
Cloud Computing Overview
What is App Engine
Why App Engine
Application Lifecycle with App Engine
Development Using App Engine
Deploying Applications
Security
Quota & Pricing
www.exmachina.ch
in <code> we trust
Cloud Computing?
Cloud computing is a style of computing in which dynamically
scalable and often virtualized resources are provided as a service
over the Internet. Users need not have knowledge of, expertise in, or
control over the technology infrastructure in the "cloud" that supports
them.
www.exmachina.ch
in <code> we trust
Big Picture
www.exmachina.ch
in <code> we trust
Pros and cons
Scale and cost Locking
Change Management Reliability
Next Generation Architecture Lack of control
Choice and Agility Security
www.exmachina.ch
in <code> we trust
Growth prediction
Before allocate resources you need to know how many people will
use your service. Intense usage of service can happen regularly.
Particular usage of your service can break down it! In these situations
allocating too many resources for this particular event can be more
expensive that normal usage of the system.
www.exmachina.ch
in <code> we trust
What is App Engine?
Google's Platform to Build Web applications on the cloud
Dynamic web server, with full support for common web tecnologies
Automatic scaling and load balancing
Transactional DataStore Model
Integration with Google Accounts through APIs.
www.exmachina.ch
in <code> we trust
Why App Engine?
Scalability
Lower Total Cost of Ownership
Rich set of APIs and local development
Ease of deployment
Web administrator console and diagnostic utilities
www.exmachina.ch
in <code> we trust
Scalability
Is a desirable property of a system, which indicates its ability to either
handle growing amounts of work in a graceful manner, or to be readily
enlarged. For example, it can refer to the capability of a system to
increase total throughput under an increased load when resources
(typically hardware) are added.
www.exmachina.ch
in <code> we trust
Lower Total cost of Ownership
Software license purchase costs. Hardware and Software deployment costs.
Hardware warranties and maintenance costs. Software license tracking
costs.Operations Infrastructure Costs.Infrastructure (floor space) costs. Cost for
electricity and cooling. Network hardware and software costs. Server hardware and
software costsTesting costs. Cost to upgrade or scalability. IT Personnel costs. . .
www.exmachina.ch
in <code> we trust
Lower Total cost of Ownership
. . . “C” level management costs. Backup and Recovery Process costs. Costs
associated with failure or outage. Diminished performance incidents (i.e. users
having to wait). C.osts of security breaches (in loss of reputation and recovery costs).
Technology training costs of users and IT staff. Audit costs. Insurance
costs.Replacement costs. Migration costs. Decommissioning costs.
www.exmachina.ch
in <code> we trust
Rich set of APIs and local development
App Engine provide a full development environment. SDK can be
used and tested locally. It provide useful tools that integrate Google
or third party services.
www.exmachina.ch
in <code> we trust
Easy of development
It provide local environment to run webapp during development. GNU/
Linux is fully supported. It can be developed using any editor but
Eclipse plugin can help. Be advised that developing scalable
application is not easy :)
www.exmachina.ch
in <code> we trust
Secure Sandbox
NO file writing, creating socket or spawn threads
NO system calls like signals or C extensions
NO process that run longer than 30 secs
JRE whitelist
www.exmachina.ch
in <code> we trust
Hard limits
10 apps 30 secs per request
1 GB bandwith per day 1 GB datastore
6.5 hours of CPU time per day 2000 emails per day
www.exmachina.ch
in <code> we trust
Billing
Outgoing bandwith $0.12 GB
Incoming bandwith $0.10 GB
CPU time $0.10 per CPU hour
Stored data $0.15 per GB month
Recipients emailed $0.0001 per recipient
www.exmachina.ch
in <code> we trust
Numbers are numbers
Currently, over 80K applications
Serving over 140M pageviews per day
Written by over 200K developers
www.exmachina.ch
in <code> we trust
www.exmachina.ch
in <code> we trust
Application Lifecycle
www.exmachina.ch
in <code> we trust
App Engine
www.exmachina.ch
in <code> we trust
Servlet API
Servlet 2.5 Container
Http Session Support
JSP Support
Uses Jetty and Jasper
NO Jetty-specific feature
NO jetty-web.xml
NO continuations
www.exmachina.ch
in <code> we trust
Webapp
/WEB-INF/web.xml
/WEB-INF/appengine-web.xml
/WEB-INF/lib
/WEB-INF/classes
/index.jsp
*
www.exmachina.ch
in <code> we trust
appengine-web.xml
<appengine-web-app>
<application>application-id</application>
<version>1</version>
<static-file>
<include path=”img/*”/>
<exclude path=”img/*something”/>
</static-file>
<ssl-enabled>true</ssl-enabled>
<sessions-enabled>true</sessions-enabled>
</appengine-web-app>
www.exmachina.ch
in <code> we trust
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
WhiteList not enforced
www.exmachina.ch
in <code> we trust
App Engine Architecture
www.exmachina.ch
in <code> we trust
Deployment
App lives at <app_id>.appspot.com, or
Custom domain with Google Apps
Command line and IDE tools
Deploying uploads
Static files
Resource files
Metadata (datastore indexes, cron jobs)
www.exmachina.ch
in <code> we trust
Admin Console
Expose information about deployed application
www.exmachina.ch
in <code> we trust
Admin Console
www.exmachina.ch
in <code> we trust
APIs
www.exmachina.ch
in <code> we trust
DataStore API
Provides the ability to store data
Transactional
Natively Partitioned
Hierarchical
Schema-less
Based on Bigtable
Not a relational database or SQL engine
www.exmachina.ch
in <code> we trust
Images API
Provides the ability to manipulate image
Transforming Images in Java
Available Image Transformations
Image Formats
Images and the Development Server
Quotas and Limits
www.exmachina.ch
in <code> we trust
Available Transformations
Resize Rotate
Flip horizontally Flip vertically
I'm Feeling Lucky Crop
www.exmachina.ch
in <code> we trust
Formats
Accepts image data in the JPEG, PNG, GIF (including animated
GIF), BMP, TIFF and ICO formats.
Can return transformed images in the JPEG and PNG formats.
www.exmachina.ch
in <code> we trust
Quota and Limits
Each Images service request counts toward the Image
Manipulation API Calls quota. An app can perform multiple
transformations of an image in a single API call.
Additional limits of 1 MB data size:
for image sent to service
for image received from service
www.exmachina.ch
in <code> we trust
Memcache API
Provides distributed in-memory key-value cache often used by
high performance scalable web applications.
www.exmachina.ch
in <code> we trust
Caching Data with JCache
import static java.util.Collections.emptyMap;
import javax.cache.*;
CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
Cache cache = cacheFactory.createCache(emptyMap());
cache.put(key, value);
cache.get(key);
www.exmachina.ch
in <code> we trust
Quota and Limits
Each Memcache call counts toward the Memcache API Calls
quota.
Additional limits of 1 MB data size:
for a cached value
www.exmachina.ch
in <code> we trust
Mail API
Provides the ability to send email messages on behalf of the
app's administrators, and on behalf of users with Google
Accounts.
www.exmachina.ch
in <code> we trust
Send Email using JavaMail
import javax.mail.*;
Session session = Session.getDefaultInstance(new Properties(), null);
InternetAddress admins = new InternetAddress("admins");
Message msg = new MimeMessage(session);
msg.setFrom(admins);
msg.addRecipient(Message.RecipientType.TO, admins);
msg.setSubject("subject");
msg.setText("text");
Transport.send(msg);
www.exmachina.ch
in <code> we trust
URL Fetch API
Provides the ability to fetch resources and communicate with
other hosts over the Internet using HTTP and HTTPS requests.
www.exmachina.ch
in <code> we trust
Fetching URLs with java.net
import java.net.*;
import java.io.*;
URL url = new URL("htp://...");
InputStream inputinputStream = new InputStreamReader(url.openStream())
BufferedReader reader = new BufferedReader(inputStream);
String line;
while ((line = reader.readLine()) != null) { . . . }
reader.close();
www.exmachina.ch
in <code> we trust
Quota and Limits
Each URL Fetch request counts toward the URL Fetch API Calls
quota.
Additional limits of 1 MB data size:
request size
response size
www.exmachina.ch
in <code> we trust
URL Fetch API
www.exmachina.ch
in <code> we trust
Users API
Provides the ability to authenticate users with Google Accounts.
www.exmachina.ch
in <code> we trust
XMPP API
Provides the ability send messages like Google Talk.
www.exmachina.ch
in <code> we trust
Task Queue API
Provides the ability to perform background processing by
inserting tasks (modeled as web hooks) into a queue.
www.exmachina.ch
in <code> we trust
Design Motivation
Build on existing Google tecnology
Provide an integrated environment
Encourage small request footprint
Encourage fast request
Maintain isolation between applications
Encourage statelessness and specialization
Required partitioned datamodel
www.exmachina.ch
in <code> we trust
Provide an Integrated Environment
Manage all apps together
Follow best practices
Some restrictions
Use their tools
Use their tools, Admin Console, All logs in one place
No machines to configure or manage, Easy deployment
www.exmachina.ch
in <code> we trust
Encourage Small Per-Request Footprints
Better utilization of App Servers
Fairness
Less Memory Usage
Limited CPU
Better use of resources
www.exmachina.ch
in <code> we trust
Encourage Fast Requests
Better utilization of appservers
Fairness between applications
Routing and scheduling agility
Runtime caching and Request deadlines
Optimistically share state between requests
Better throughput; Fault tolerance; Better use of resources
www.exmachina.ch
in <code> we trust
Maintain Isolation Between Apps
Safety
Predictability
Certain system calls unavailable
Security
Performance
www.exmachina.ch
in <code> we trust
Encourage Statelessness and Specialization
App Server performance
Load balancing
Fault tolerance
Use API calls
Automatic load balancing and Fault tolerance
Less code for you to write; Better use of resources
www.exmachina.ch
in <code> we trust
Require Partitioned Data Model
The Datastore
Data model + Indexes
Reads are fast, writes are slower
Design your schema once
No need to re-architect for scalability
More efficient use of cpu and memory
www.exmachina.ch
in <code> we trust
Work Together
App Engine and Amazon Web Services like Elastic Compute Cloud can
work well togheter!
EC2 can be used to perform long running task.
S3 can be used to store files bigger than 1MB.
www.exmachina.ch
in <code> we trust
Amazon Web Services
www.exmachina.ch
in <code> we trust
App Engine and AWS
www.exmachina.ch
in <code> we trust
App Engine and AWS
www.exmachina.ch
in <code> we trust
Google App Engine?
luca.marrocco@gmail.com
www.exmachina.ch
in <code> we trust
Bibliografia
http://code.google.com/appengine/
http://www.slideshare.net/ajdevries/presentation-google-app-engine-4-java
http://www.slideshare.net/rajdeep/introduction-to-google-app-engine-presentation
http://code.google.com/events/io/sessions/FromSparkPlugToDriveTrain.html
http://code.google.com/events/io/sessions/SofterSideofSchemas.html
http://code.google.com/events/io/sessions/AppEngineNowJava.html
http://en.wikipedia.org/wiki/Scalability
www.exmachina.ch
in <code> we trust
1 comments
Comments 1 - 1 of 1 previous next Post a comment