google app engine para lean startups: the good, the bad and the ugly

56
Google App Engine para Startups Enxutas: The Good, The Bad and The Ugly Marcio Marchini [email protected]

Upload: pet-computacao

Post on 24-May-2015

2.619 views

Category:

Education


0 download

DESCRIPTION

Mais da metade da geração Y americana quer empreender, e na área de High Tech isso significa startups. Mas montar uma startup enxuta requer queimar etapas que devem ser encaradas excesso de peso em seus concorrentes. Uma dessas escolhas seria a utilização de uma Platform as a Service, e dentre elas uma escalável e NoSQL como Google App Engine(GAE). Nessa apresentação cobriremos aspectos positivos, negativos e grotescos em GAE segundo nossos experimentos Java e Python sobre a mesma desde 2011. Se você prefere aprender com os erros dos outros e está curioso sobre Cloud Computing com GAE, essa apresentação é pra você.

TRANSCRIPT

Page 1: Google app engine para lean startups: the good, the bad and the ugly

Google App Engine para Startups Enxutas: The Good, The Bad and The Ugly

Marcio Marchini [email protected]

Page 2: Google app engine para lean startups: the good, the bad and the ugly

Explicando o Título

1. The Good, The Bad and The Ugly

(Um clássico a ser assistido…)

Page 3: Google app engine para lean startups: the good, the bad and the ugly

Explicando o Título

2.  Startups Enxutas

(Um bom livro a ser lido…)

Page 4: Google app engine para lean startups: the good, the bad and the ugly

Explicando o Título

3.  Goole App Engine

(Uma Platform as a Service a ser explorada…)

Page 5: Google app engine para lean startups: the good, the bad and the ugly

PaaS, IaaS, etc

Fonte: Wikipedia

Ex. EC2

Ex. GAE

Ex. VOCÊ!

Page 6: Google app engine para lean startups: the good, the bad and the ugly

GAE Datastore: Comparativo

Imagem do Artigo: “Banco de dados como serviço” / revista “tema” / SERPRO

Page 7: Google app engine para lean startups: the good, the bad and the ugly

GAE: PaaS

Vamos ao que Interessa pra sua Startup Enxuta…

Page 8: Google app engine para lean startups: the good, the bad and the ugly

Lição Lean Startup #1: Web Site Estático Escalável

1.  Uma App no App Engine pode ter parte estática e parte dinâmica (Python, Java, etc)

2.  O Web Site de sua empresa pode começar 100% estático

3.  E pode ser escalável… (brabilhões de visitantes)

4.  E sem admin Linux, EC2 etc… ($$$)

5.  E sem pagar taxa de hosting pra uso normal… ($)

6.  E sem se incomodar com DDoS etc

7.  …

Page 9: Google app engine para lean startups: the good, the bad and the ugly

Bebemos o Próprio Champagne… (nosso site é uma app GAE)

Page 10: Google app engine para lean startups: the good, the bad and the ugly

Matamos a Cobra e Mostramos o Pau: Site Estático no GAE

1.  Vamos escolher um site estático qualquer na web o e vamos colocá-lo no GAE. Exemplo aleatório: http://www.promote-web-sites.com

2.  Vamos fazer download de suas páginas: wget --mirror -p --convert-links -P . http://www.promote-web-sites.com

3.  Faz de conta que esse é o meu site. Vamos colocá-lo no GAE? è Mova as páginas HTML para uma pasta static , dentro do nossa pasta betdevgaenosql mv ./www.promote-web-sites.com/* /Users/mqm/betdevgaenosql/static

Page 11: Google app engine para lean startups: the good, the bad and the ugly

(2/4): Site Estático no GAE

4.  Editemos app.yaml para poder servir páginas estáticas

Page 12: Google app engine para lean startups: the good, the bad and the ugly

(3/4): Site Estático no GAE – Testando Localmente

5.  Clique Run (botão verde)

6.  Visite: http://localhost:8080/

7.  Site estático!!

Page 13: Google app engine para lean startups: the good, the bad and the ugly

(4/4): Site Estático no GAE - Deploy

8.  Clique Deploy no GAE Launcher (botão azul)

9.  Visite: http://betdevgaenosql.appspot.com/

10. Site estático!! (com URL feia L)

Page 14: Google app engine para lean startups: the good, the bad and the ugly

Recapitulando

•  Uma Google App (em Python, Java, etc) pode servir conteúdo estático

•  Podes fazer upload de seu site hoje

•  Mas… como coloco uma URL raiz com meu domínio (ex. www.betterdeveloper.net) ao invés de *.appspot.com ?

Page 15: Google app engine para lean startups: the good, the bad and the ugly

Lição Lean Startup #2: Sua Página, Seu Domínio, GAE

1.  Registre seu domínio em registro.br ou web.com ou outro Registrar qualquer

2.  Crie uma conta (gratuita) em www.ZoneEdit.com

3.  Adicione uma Zone no ZoneEdit, correspondente ao seu domínio

4.  No seu Registrar, aponte o DNS para os valores do ZoneEdit.com (ex. ns10.zoneedit.com , etc)

5.  Adicione a entrada A e CNAME conforme abaixo

Page 16: Google app engine para lean startups: the good, the bad and the ugly

Sua Página, Seu Domínio, GAE

6.  Crie uma conta gratuita Google Apps (<=10 contas no seu domínio)

7.  Cria sua Google App nesse domínio

8.  Crie o mapeamento de www no Google App para sua App

9.  Deverá funcionar, igual ao www.betterdeveloper.net

Page 17: Google app engine para lean startups: the good, the bad and the ugly

Lição Lean Startup #3: Versões Distintas, Rollback

1.  Temos que habilitar a versão 2 do site

2.  Habilite o radio button, clique Make Default

3.  Clique no “2”ao lado do radio button. Ele vai disparar a versão 2 do site

4.  Clique no “1”ao lado do radio button. Ele vai disparar a versão 1 do site (original)

Page 18: Google app engine para lean startups: the good, the bad and the ugly

Lição Lean Startup #4: Versione seu conteúdo

1.  Use Git ou Svn pra versionar os fontes do seu site. Use TAGs por exemplo pra mapear pra versão ativa no ar (slide anterior)

2.  Use uma conta gratuita xp-dev.com – pode ter 1 projeto não Open Source, gratuitamente

3.  Agora você tem rastreabilidade e governança de fontes e versões no ar, gratuitamente. Fontes na Cloud (XP-Dev). “Binário”/site na Cloud (GAE)”. Super Lean.

4.  Ative o TRAC como sistema de tickets no XP-DEV. Pronto, agora até suas sprints/backlogs/feature requests/bug fixes tem Roadmap na web e governança na empresa.

Page 19: Google app engine para lean startups: the good, the bad and the ugly

Hello World no Estilo GAE

Hello, World!

Page 20: Google app engine para lean startups: the good, the bad and the ugly

GAE Hello World & Elasticidade (2011/06, Wicket)

http://<helloworld>.appspot.com , simulando 250 usuários concorrentes por 10 minutos com http://sourceforge.net/projects/dieseltest/

Page 21: Google app engine para lean startups: the good, the bad and the ugly

GAE Hello World & Elasticidade (2011/06, Wicket)

Page 22: Google app engine para lean startups: the good, the bad and the ugly

GAE “Hello World” de Datastore (2011/06, Wicket)

CRUD de Redes de Hotéis e Hotéis

Page 23: Google app engine para lean startups: the good, the bad and the ugly

GAE “Hello World” de Datastore (2011/06, Wicket)

GUI versus Datastore

Page 24: Google app engine para lean startups: the good, the bad and the ugly

The Good: J

(Coisas legais/boas no GAE)

Page 25: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE - Performance

•  5 milhões de pageviews / mês gratuitamente. Chega pra ti?

•  Memchache distribuído, sem você precisar instalar/configurar

•  Conteúdo estático servido por servidores dedicados, transparentemente. Não precisas penar configurando load balancers / nginx etc e tal.

•  Mantém sua app em RAM o máximo que dá (performance)

•  Suporta tasks/background, no estilo cron

•  Logging fácil, memcache fácil

•  Utiliza o performático Jetty, envenenado: http://www.infoq.com/news/2009/08/google-chose-jetty

•  Suporte a SDPY na sua app http://dev.chromium.org/spdy/spdy-whitepaper

Page 26: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE – Traffic Splitting

•  A/B Testing etc etc

Page 27: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE – IDEs etc

•  Suporte a Python, Go, Java (e linguagens que rodam na JVM)

•  Roda frameworks tipo Java Apache Wicket, Python CherryPy. Suporta GWT etc. https://spreadsheets.google.com/a/betterdeveloper.net/pub?key=pRJ_0hajVrhacLjp3HqD5ew

•  Suportado por Eclipse (plugin GAE), PyCharm etc

•  Suporta Ant

•  Podes testar localmente antes

•  Console interativo Python – rode snippets direto no servidor, “peek/poke”

•  Sua app pode receber email, entra como http request (GAE cuida disso).

Page 28: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE - Storage

•  Datastore “schemaless”. Fácil prototipar e evoluir.

•  O NoSQL pode buscar baseado em propriedades

•  Versão dev local analisa perfil de uso e já otimiza índices do datastore

•  SDK suporta upload/download de dados em modo “bulk”

•  JPA significa que podes entrar/sair do GAE com mais facilidade (evita lock-in). Well… (veja The Ugly)

•  Datastore pode gerar unique keys automaticamente

•  Memcache obedece standard JCache

•  Memcache viewer no Python SDK

•  Podes fazer sync GAE-NoSQL ßà MySQL externo com https://github.com/k7d/approcket/wiki

Page 29: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE – Storage Relacional

•  Não é só NoSQL. MySQL também suportado (Mas sem quota gratuita)

•  http://googleappengine.blogspot.com.br/2012/05/cloud-sql-pick-plan-that-fits-your-app.html

•  https://developers.google.com/cloud-sql/

Page 30: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE

•  Console pra administração

•  Múltiplas versões da app rodando concorrentemente

•  Podes fazer uma app só pra sua “Intranet” – apenas membros do seuDominio.com tem acesso

•  10 apps GAE por developer

•  Sem Ads, mesmo nas apps free / conta free (ex. Gmail)

•  Pode-se definir um limite máximo de custo por dia

•  Boa integração com APIs Google: login, gtalk, imagens, etc

•  Paypal ok: http://www.dzone.com/links/setting_up_paypal_ipn_handling_on_google_app_engi.html

•  Possível mandar email pra app via XMPP, do console, pra testes

Page 31: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE

•  Duas implementações novas, não proprietárias

•  http://en.wikipedia.org/wiki/AppScale It has support for Python, Go, and Java applications, taking the open source SDK provided by Google App Engine and implementing scalable services such as the datastore, memcache, blobstore, users API, and channel API.

•  http://code.google.com/p/typhoonae/ (BETA)

Page 32: Google app engine para lean startups: the good, the bad and the ugly

Coisas boas GAE

•  Google Data Centers http://www.google.com/about/datacenters/inside/index.html

Page 33: Google app engine para lean startups: the good, the bad and the ugly

The Bad: L

(Coisas ruins no GAE – na nossa opinião)

Page 34: Google app engine para lean startups: the good, the bad and the ugly

Coisas ruins GAE…

•  Livros obsoletos. Exemplo: dica de “main”/Python pra cache em Programming Google App Engine: não mais necessário com Python 2.7 (veja https://developers.google.com/appengine/docs/python/python25/migrate27#wsgi )

Page 35: Google app engine para lean startups: the good, the bad and the ugly

Coisas ruins GAE…

•  Feito pra requests que demorem <1s. Se demorar >60s, você é assassinado (no livro – obsoleto - fala 30s, mas https://developers.google.com/appengine/docs/python/runtime#The_Request_Timer diz 60.

•  File Upload? Que mais demora >60s na web?

•  Async URL fetch serve pra mitigar a maioria dos cenários

Page 36: Google app engine para lean startups: the good, the bad and the ugly

New Relic não Rola L

“The restrictions that exist under Google App Engine, such as those on background threads, as well as how processes are managed, mean that the Python agent as it is implemented at present will not work as is. There are no plans at this point to support Google App Engine.”

è Use o Dashboard “toco-duro” GAE… L

Page 37: Google app engine para lean startups: the good, the bad and the ugly

Apple iOS Push Notification não Rola L

Sandbox: não podes abrir conexão socket pros servidores de Push da Apple

è Precisas de uma máquina na EC2 etc que responda à sua app no GAE via REST e essa sim faz o push pra Apple. Sugestão: RabbitMQ/REST http://code.google.com/p/amqp-rest/

è Ou: espera o Beta graduar: http://code.google.com/p/googleappengine/issues/detail?id=1164

Page 38: Google app engine para lean startups: the good, the bad and the ugly

WebSockets não rola L

Algo tipo Trello, que usa WebSockets (segundo artigo publicado), não funciona pelo mesmo motivo (conexões socket persistentes / longas) § Mas tem a Channel API: https://developers.google.com/appengine/docs/java/channel/overview The Channel API creates a persistent connection between your application and Google servers, allowing your application to send messages to JavaScript clients in real time without the use of polling. This is useful for applications designed to update users about new information immediately.

è Sentiu-se atolando na areia movediça da plataforma proprietária?

Page 39: Google app engine para lean startups: the good, the bad and the ugly

Minha Framework Web Favorita não vem pré-carregada L

CherryPy não vem pré-carregada https://developers.google.com/appengine/docs/python/tools/libraries27

èTens que empacotar o zip junto e dinamicamente adicionar no path

è Ou seja: não é problema, funciona ok

Page 40: Google app engine para lean startups: the good, the bad and the ugly

Coisas ruins GAE

•  Modelo limitado/Sandbox – mais proteção, mas… mais restrição

•  (2011) Não suporta(va) Full Text Search (pense CMS). Aparentemente ok em 2012: http://googleappengine.blogspot.com.br/2012/05/looking-for-search-find-it-on-google.html

•  (2011) Algumas operações, só com SDK de linha de comando. Inexistência de GUI Launcher pra Linux (só Windows e Mac).

•  Nem todas APIs oficiais são implementadas (ex trivial: Thread/ThreadGroup Java)

•  Muita coisa JPA aponta pra JDO, que está obsoleto

•  (2011) Console Java mais limitado que o Python

•  (2011) Servidor DEV/PC não suporta “background tasks” no Python (GAE Era Preview até Setembro de 2011!!!)

Page 41: Google app engine para lean startups: the good, the bad and the ugly

Coisas ruins GAE

•  Domínio customizado requer conta Google Apps (mas é free pra 10 contas de usuário/colaborador/funcionário/whatever)

•  Ativar 1 conta GAE/Developer requer 1 telefone celular. 3 domínios? Arrume 3 celulares J

•  Não faz routing de domínio puro (foo.com) pra app. Tem que ser algo como www.foo.com

•  è Se usares www, tens que primeiro habilitar Sites, mudar esse de www pra www2 ou algo assim, pra sua app poder servir www.seuDominio.com

•  Tipo de autenticação da App não pode mudar após criado o seu ID

•  Multithreaded p/ Python demorou a ser ativado (só agora com Python 2.7). Era CGI ao invés de WSGI. (Mas Java já era MT ok)

Page 42: Google app engine para lean startups: the good, the bad and the ugly

Coisas ruins GAE: PhD pra entender Índices

•  Todas as queries usam índices

•  Alguns índices são gerados automaticamente pra você

•  Queries mais elaboradas precisam de índices pré-definidos/criados no arquivo index.yaml

•  Caso a query precise de um índice e esse não exista ainda, vai dar erro/exceção

•  O sistema tenta criar os índices pra você baseado nas queries de desenvolvimento DEV/PC

Page 43: Google app engine para lean startups: the good, the bad and the ugly

Google Could SQL é pago

è Não dá pra ser enxuto se quiseres SQL ao invés de NoSQL

Page 44: Google app engine para lean startups: the good, the bad and the ugly

Alguns Limites em geral

è Fique atento… https://developers.google.com/appengine/docs/python/runtime#Quotas_and_Limits

Page 45: Google app engine para lean startups: the good, the bad and the ugly

Limites Free à Pago

è Datastore:

è Log:

Page 46: Google app engine para lean startups: the good, the bad and the ugly

Limites Free à Pago

è Bandwidth:

è tasks:

Mais: https://developers.google.com/appengine/docs/quotas

Page 47: Google app engine para lean startups: the good, the bad and the ugly

The Ugly: LLL

(Coisas bem ruins no GAE)

Page 48: Google app engine para lean startups: the good, the bad and the ugly

Coisas bem ruins GAE

•  Acesso SSH? Esquece

•  Precisou de uma ferramenta extra, tipo Sphinx? Esquece! Lembre: Não tens um console Linux. PaaS!

Page 49: Google app engine para lean startups: the good, the bad and the ugly

Coisas bem ruins GAE: HTTPS

•  Não suporta (va) HTTPS se sua app está com um domain “bonito” tipo foo.bar.com (mas OK na forma foo.appspot.com). http://code.google.com/p/googleappengine/issues/detail?id=792

•  Isso vai me dificultar adicionar pagamento online VISA no www.betterdeveloper.net

•  Teoricamente arrumado em 06/2012 com SNI (Server Name Indication) @ US$9/mês ou VIP (Virtual IP) @ US$99/mês - http://googleappengine.blogspot.com.br/2012/06/google-app-engine-170-released-at.html

Page 50: Google app engine para lean startups: the good, the bad and the ugly

Coisas bem ruins GAE: JPA “Alfa” (tvz ok em 2012?)

•  (2011) Implementação JPA em cima de Datanucleous não era oficialmente suportada pelo pessoal Datanucleous. Muita limitação, muita dor de cabeça!!!

•  Exemplo: Uma entidade "pai"e uma "filha" nao podem ambas ter @Id sendo um Long. A do filho tem que usar a classe proprietária Key da Google. Vejam http://code.google.com/p/datanucleus-appengine/issues/detail?id=26 . Foi pro espaço sua portabilidade JPA!!!!

•  è Aparentemente arrumaram em 2012: http://code.google.com/p/datanucleus-appengine/source/browse/branches/2_0_0/dist/RELEASE_NOTES.ORM

Page 51: Google app engine para lean startups: the good, the bad and the ugly

Coisas bem ruins GAE: App Engine Data != Big Data

1.  JÁ QUE Google tem MapReduce & tem NoSQL Datastore

2.  E JÁ QUE GAE roda na infra Google

•  ENTÃO OBVIAMENTE minha GAE App pode ter BigData e eu fazer MapReduce nos dados, certo? NÃO! Infelizmente, tens que:

a.  OU usar o produto BigQuery https://cloud.google.com/products/big-query

b.  OU usar Library MapReduce http://code.google.com/p/appengine-mapreduce/ , https://developers.google.com/appengine/docs/python/dataprocessing/overview (“ALFA”)

•  Que por ora só tem o Mapper API (sem Reduce) http://googleappengine.blogspot.com.br/2010/07/introducing-mapper-api.html?m=1 , https://developers.google.com/appengine/articles/mr/mapper

Page 52: Google app engine para lean startups: the good, the bad and the ugly

Coisas bem ruins GAE: Queries impossíveis GQL

è Testar 2 inequalidades de 2 propriedades distintas não rola

Page 53: Google app engine para lean startups: the good, the bad and the ugly

Coisas ruins GAE

•  Portabilidade Problemática. Será que http://en.wikipedia.org/wiki/AppScale é viável? Não testei.

è Sentiu-se atolando na areia movediça da plataforma proprietária?

Page 54: Google app engine para lean startups: the good, the bad and the ugly

Conclusão

•  Às Vezes o Barato Sai Caro… O Desafio é escolher o barato certo (Linux Admin ou GAE Fees?)

•  Try Before You Buy

•  Your Mileage May Vary

•  “Valeu à Pena? Tudo Vale a Pena se a Alma Não é Pequena” --– Fernando Pessoa

•  Investigue tb Heroku, Azure, etc

•  Investigue tb Do-It-Yourself com Amazon EC2 e/ou Amazon SimpleDB e/ou Amazon MapReduce (Hadoop)

Page 55: Google app engine para lean startups: the good, the bad and the ugly

Obrigado! E Lembre-se…

“To Know and not to do, is not to know”

http://en.wikipedia.org/wiki/Google_App_Engine

Page 56: Google app engine para lean startups: the good, the bad and the ugly

Slides em PDF no Site

http://www.BetterDeveloper.net/downloads.html