app engine kick start

26
App Engine Kick Start @tomucha

Upload: tomas-zverina

Post on 28-Nov-2014

5.148 views

Category:

Documents


5 download

DESCRIPTION

Tomuchovo prednaska o App Engine na GUG CVUT.

TRANSCRIPT

Page 1: App Engine Kick Start

App Engine

Kick Start@tomucha

Page 2: App Engine Kick Start

Multimedia atelier s. r. o.

Page 3: App Engine Kick Start

Multimedia atelier s. r. o.

Page 4: App Engine Kick Start

memeReactor

Page 5: App Engine Kick Start

Cloud Computing

virtualization

SOA

SaaS

scalabity

distributed

YOU

YOURADMIN

Page 6: App Engine Kick Start

Cloud Computing

Just like water from the tap in your kitchen, cloud computing services can be turned on or off quickly as needed.

Vivek Kundra, 1st CIO of USA

“It's stupidity. It's worse than stupidity: it's a marketing hype campaign.”

Richard Stallman, GNU founder

Page 7: App Engine Kick Start

Škálovatelnost (nutná, ...)

12:00 18:00 24:00 6:00 12:00 18:00 24:00 6:00 12:00 18:00 24:00 6:00

Peak3 nodes

1 node

Page 8: App Engine Kick Start

(… nikoliv postačující podmínka úspěchu)

12:00 18:00 24:00 6:00 12:00 18:00 24:00 6:00 12:00 18:00 24:00 6:00 12:00

TechCrunchefect

Page 9: App Engine Kick Start

Škálování

Vertical scaling – posiluju počítač

Vertical partitioning – rozděluju služby

Horizontal scaling – přidávám nody

• load balancing

• dynamické škálování

• sessions

• database a další sdílené zdroje (FS, cache, ...)

• péče o hardware

Page 10: App Engine Kick Start

Možnosti

Amazon Elastic Compute Cloud (Amazon EC2)

Amazon Simple Storage Service (Amazon S3)

Windows Azure

Rackspace.com

...

Page 11: App Engine Kick Start

App Engine

Hosting

API / Framework

IDE plugin / SDK

Page 12: App Engine Kick Start

App Engine vs. Amazon AWS

App Engine mrak strojů

hosting

storage

scalability

pay for what you use

different OS, languages

framework / API

Page 13: App Engine Kick Start

App Engine – A jako v praxi teda?

WAR

Page 14: App Engine Kick Start

App Engine – Omezení (Sandbox)

Bezpečnost

přístup na FS

práce se sockety

thready

java.lang.System / GC

reflexe

Škálovatelnost

NoSQL

joins, group by, agregate

unique

30s limit

quoty

Page 15: App Engine Kick Start

App Engine – K čemu je, k čemu není

Jo

WWW

eShop

“Twitter”

“Flickr”

Ne

finanční software

UDP herní server

“YouTube”

velké výpočty

Page 16: App Engine Kick Start

App Engine – Framework

Sessions – musí se zapnout

Images – manipulace alá Picassa

Channel – push to client (+ JS knihovna)

Mail / URLFetch / XMPP - komunikace

MemCache – distributed cache

Task Queue / Cron – asynchronní úlohy

Users – login via Google Account

Page 17: App Engine Kick Start

Demo

http://code.google.com/appengine/

http://code.google.com/appengine/docs/java/tools/eclipse.html

Page 18: App Engine Kick Start

Databáze

BigTable → BIG MIND SHIFT

• gigantická HashMapa HashMap

• WWW index, Earth, Finance, ...

nemá datový model

preindexed queries, joins, 2x “<”

přístup

• nativní API App Engine

• Java Data Objects – JDO

• Java Persistence Api – JPA

Page 19: App Engine Kick Start

Databáze – Primary Keys

Key

• appId

• namespace

• Entity kind

• id / name

• parent

Entity employee = new Entity("Employee");

Entity employee = new Entity("Employee", "asalieri");

KeyFactory.createKey(Employee.class.getSimpleName(), "[email protected]");

Page 20: App Engine Kick Start

Databáze – Transakce

Faktura

Řádek 1

Řádek 2

Produkt 1

Produkt 2

Entity Group

Page 21: App Engine Kick Start

Databáze – JDO relationships

Owned One-to-One Relationships (záznam + detaily)

• jo – může přinést výhody

Owned One-to-Many Relationships (faktura + řádky)

• jo, vytváří EntityGroup

Unowned Relationships (člověk a oblíbené jídlo, n:m)

• ne-e, ručně, přes Key

Page 22: App Engine Kick Start

Databáze - Optimistic Concurrency Control

int retries = 3;

while (true) {

    Transaction txn = datastore.beginTransaction();

    try {

        // do stuff

        txn.commit();

        break;

    } catch (ConcurrentModificationException e) {

        if (retries == 0) throw e;

        ­­retries;

    } finally {

        if (txn.isActive()) txn.rollback();

    }

}

Page 23: App Engine Kick Start

memeReactor - pitevna

                try {

                    chain.doFilter(hr, response);

                } finally {

                    try {

                        final PersistenceManager pm = PMF.get();

                        if (pm.currentTransaction().isActive()) {

                            pm.currentTransaction().rollback();

                        }

                    } catch (Exception e) {

                    }

                    PMF.close();

                }

Page 24: App Engine Kick Start

memeReactor - pitevna

transaction(new TransactionCallback() {

@Override

public void runInTransaction(PersistenceManager pm) {

// do stuff

}

});

Begin, Commit, Rollback, repeat, ...

Page 25: App Engine Kick Start

AppEngine - tipy

Zapomeňte na SQL a normální formy (s rozmyslem)

• denormalizace

• kolekce a pole jako datový typ

Zapomeňte na ORM (nebo alespoň relationships)

Testujte “pod zátěží” a ne jen na localhost

<%@ page contentType="text/html;charset=UTF­8" language="java" isELIgnored="false" %>

Page 26: App Engine Kick Start

Q&A