Building Scalable Web Apps with Python and Google Cloud Platform. Dan Sanderson, April 2015

Similar documents
Developing Solutions for Google Cloud Platform (CPD200) Course Agenda

Cloud Computing Platform as a Service

Google GCP-Solution Architects Exam


Seminar report Google App Engine Submitted in partial fulfillment of the requirement for the award of degree Of CSE

Optimizing Your App Engine App

PROGRAMMING GOOGLE APP ENGINE WITH PYTHON: BUILD AND RUN SCALABLE PYTHON APPS ON GOOGLE'S INFRASTRUCTURE BY DAN SANDERSON

Developing with Google App Engine

nacelle Documentation

Python web frameworks

Google Cloud Platform for Systems Operations Professionals (CPO200) Course Agenda

Index. Big Data analytics, , 355 BigQuery ad-hoc system, 236 Apache access log files AccessLog declaration, 240 commas as delimiters, 242

PaaS Cloud mit Java. Eberhard Wolff, Principal Technologist, SpringSource A division of VMware VMware Inc. All rights reserved

Homework #7 Google Cloud Platform

CACHE ME IF YOU CAN! GETTING STARTED WITH AMAZON ELASTICACHE. AWS Charlotte Meetup / Charlotte Cloud Computing Meetup Bilal Soylu October 2013

webapp2 Documentation

Google App Engine: Java Technology In The Cloud

WebJobs & Azure Functions in modern and Serverless applications. Paris Polyzos Software Engineer at ZuluTrade Inc Microsoft Azure MVP

How to go serverless with AWS Lambda

App Engine MapReduce. Mike Aizatsky 11 May Hashtags: #io2011 #AppEngine Feedback:

django-cas Documentation

Getting the most out of Spring and App Engine!!

Django MFA Documentation

Contents. Chapter 1: Google App Engine...1 What Is Google App Engine?...1 Google App Engine and Cloud Computing...2

Rekall. Rekall Agent - OSDFCon Forensics. We will remember it for you wholesale! Michael Cohen

Western Michigan University

AWS Lambda. 1.1 What is AWS Lambda?

GAE Google App Engine

Developing Enterprise Cloud Solutions with Azure

Managing Dependencies and Runtime Security. ActiveState Deminar

Serverless Architecture Hochskalierbare Anwendungen ohne Server. Sascha Möllering, Solutions Architect

Building Microservices with the 12 Factor App Pattern

Q u e s t i o n m a r k C o n f e r e n c e

Kubernetes The Path to Cloud Native

Microservices without the Servers: AWS Lambda in Action

Deployability. of Python. web applications

Verteego VDS Documentation

Building Applications with IOx

Signals Documentation

ArcGIS for Server: Administration and Security. Amr Wahba

What s New in K8s 1.3

What s New in K8s 1.3

FROM VSTS TO AZURE DEVOPS

mri Documentation Release Nate Harada

DOWNLOAD OR READ : GOOGLE APP ENGINE JAVA AND GWT APPLICATION DEVELOPMENT PDF EBOOK EPUB MOBI

Django-Style Flask. Cody Lee SCALE12x Feb 22, git clone

Google & the Cloud. GData, Mashup Editor, AppEngine. Gregor Hohpe Software Engineer Google, Inc. All rights reserved,

Rapid Development with Django and App Engine. Guido van Rossum May 28, 2008

ClickToCall SkypeTest Documentation

A Sample Approach to your Project

CCS Lab FAQ: Using Google App Engine to host websites

Flask-Testing Documentation

Deccansoft Software Services

Chris Calloway for Triangle Python Users Group at Caktus Group December 14, 2017

Python for Google App Engine

Kinto Documentation. Release Mozilla Services Da French Team

Developing Microsoft Azure Solutions (70-532) Syllabus

Let s say that hosting a cloudbased application is like car ownership

Lab 2 Third Party API Integration, Cloud Deployment & Benchmarking

IoC Documentation. Release Thomas Rabaix

Systems Integration in the Cloud Era. Kai Wähner, MaibornWolff et al GmbH

flask-jwt Documentation

IBM Bluemix compute capabilities IBM Corporation

Homework 9: Stock Search Android App with Facebook Post A Mobile Phone Exercise

Cloud Computing. Chapter 3 Platform as a Service (PaaS)

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. TurboGears

Cloud platforms. T Mobile Systems Programming

Lotus IT Hub. Module-1: Python Foundation (Mandatory)

Command Execution in Heterogeneous Network at Facebook Scale Surinder Singh

Tomasz Szumlak WFiIS AGH 23/10/2017, Kraków

ITP 342 Mobile App Development. APIs

Cloud Computing 4/17/2016. Outline. Cloud Computing. Centralized versus Distributed Computing Some people argue that Cloud Computing. Cloud Computing.

Introduction to PaaS and IaaS Cloud Computing. Roberto Beraldi

AWS Lambda: Event-driven Code in the Cloud

Vishesh Oberoi Seth Reid Technical Evangelist, Microsoft Software Developer, Intergen

DataMan. version 6.5.4

Salt Administration I Training Syllabus

EXPERIENCES MOVING FROM DJANGO TO FLASK

So, I have all these containers! Now what?

Platform as a Service (PaaS)

Jaesun Han (NexR CEO & Founder)

" Qué me estás container?" Docker for dummies

Developing Microsoft Azure Solutions

Pontoon An Enterprise grade serverless framework using Kubernetes Kumar Gaurav, Director R&D, VMware Mageshwaran R, Staff Engineer R&D, VMware

Connect and Transform Your Digital Business with IBM

Part2: Let s pick one cloud IaaS middleware: OpenStack. Sergio Maffioletti

Embedded type method, overriding, Error handling, Full-fledged web framework, 208 Function defer, 31 panic, 32 recover, 32 33

Application Container Cloud

vmpooler pdxdevops : April 2015

Cloud-Driven Spatial Intelligence

Flask Web Development Course Catalog

django-baton Documentation

Microservices. Chaos Kontrolle mit Kubernetes. Robert Kubis - Developer Advocate,

Build Native-like Experiences in HTML5

DISQUS. Continuous Deployment Everything. David

Biostar Central Documentation. Release latest

Hybrid Cloud Automation using Cisco CloudCenter API

Flask-Assets Documentation

USING NGC WITH GOOGLE CLOUD PLATFORM

IBM Planning Analytics Workspace Local Distributed Soufiane Azizi. IBM Planning Analytics

Transcription:

Building Scalable Web Apps with Python and Google Cloud Platform Dan Sanderson, April 2015

June 2015 pre-order now

Agenda Introducing GCP & GAE Starting a project with gcloud and Cloud Console Understanding request handlers and instances Using Python libraries and frameworks Using Flask Testing Deploying, monitoring, debugging

Google Cloud Platform Computation Networking Data storage Data analysis Deployment, monitoring, source control, access control, services Scaling infrastructure

Google Cloud Platform Web applications and services Gaming and mobile backends Scientific computing Video and graphics rendering

Google Cloud Platform Computation and networking Google App Engine (GAE) Google Container Engine (GKE) Google Compute Engine (GCE)

Google Cloud Platform Computation and networking + Managed VMs (beta)

Google Cloud Platform Data storage and analysis Google Cloud Datastore Google Cloud SQL Google Cloud Storage

Google App Engine Scalable serving infrastructure optimized for web apps High level of abstraction Streamlined, sandboxed, language-specific Scalable services (Some services specific to App Engine)

Google App Engine Easy to deploy, easy to manage Pay only for what you use Free tier, daily allocation Preview launched in 2008 as Python-only; Java, Go, PHP added later

Setting up a development environment Cloud SDK: http://cloud.google.com/sdk/ The gcloud command Python 2.7 git pip, virtualenv

gcloud Authentication Project set-up Component installation and management Service-specific tools

gcloud App Engine SDK, Python libraries App Engine development server Development server console App Engine deployment

Cloud Console https://console.developers.google.com/

Demo

gcloud gcloud auth login gcloud init <project> creates.gcloud file, clones git repo gcloud app run app.yaml gcloud app deploy app.yaml (gcloud preview app )

Instances and Request Handlers

Services App handlers Datastore Memcache FE cache AE FE Task Queue URL Fetch Static file handlers Mail Blobstore XMPP Channel

Instances and Request Handlers Request handlers are ephemeral: now you see them, now you don t Can t rely on data persistence between requests Use storage services to persist data

Request handler Request handler Request handler Request handler

Instances and Request Handlers In practice, app initialization is expensive An app instance is long running, can handle multiple requests in its lifetime Environment initialized; instance memory loaded Started and stopped as needed Can t rely on a single user s session to go to the same instance

Instance Request handler

Instance Request handler

Instance Instance Instance Request handler Request handler Request handler

Instance Instance Instance Request handler Request handler Request handler Request handler Request handler Request handler threading enabled

Instance Instance Instance Request handler Request handler Request handler Request handler Request handler Request handler threading enabled

Instance Instance Instance Request handler Request handler Request handler Request handler threading enabled

The Python Runtime Environment

Runtime Environment Sandboxing Data isolation Performance isolation Python 2.7: app code must be Python only Sandboxing scalability

Runtime Environment Limits Request timer Restricted access to filesystem, sockets More performance isolation: RAM, CPU Data sizes: requests, responses, API calls, storage objects Limits scalability

Python Libraries Runtime includes standard lib and GAE libs automatically App code must be pure Python Can add pure Python libs to your app code App config can request specific libs be added

Python Libraries standard libraries GAE libraries application code

Python Libraries Python 2.7 standard library GAE libraries (google.appengine ) Runtime / dev server has GAE libs on path already For other scripts, like test runners: import sys sys.path.insert(0, /google-cloud-sdk/platform/ google_appengine/ )

Python Libraries standard libraries GAE libraries application code

Python Libraries standard libraries GAE libraries application code./lib/

Python Libraries % mkdir./lib % pip install -t lib Flask==0.10

Python Libraries % mkdir./lib % pip install -t lib Flask==0.10 # appengine_config.py from google.appengine.ext import vendor vendor.add( lib )

Python Libraries % mkdir./lib % pip install -t lib Flask==0.10 # appengine_config.py from google.appengine.ext import vendor vendor.add( lib ) #.gitignore lib/*

Python Libraries standard libraries GAE libraries application code./lib/

Python Libraries standard libraries GAE libraries requested libraries application code./lib/ app.yaml: libraries:

Python Libraries django endpoints jinja2 lxml markupsafe matplotlib MySQLdb numpy PIL protorpc PyAMF pycrypto setuptools ssl webapp2 webob yaml

Python Libraries # app.yaml libraries: - name: jinja2 version: 2.6 - name: markupsafe version: 0.15

Python Libraries standard libraries GAE libraries requested libraries application code./lib/ app.yaml: libraries:

Python Libraries Use virtualenv to contain requested libraries in your development environment. % virtualenv venv % source venv/bin/activate (venv)% pip install jinja2==2.6

Python Libraries Use pip requirements files to install and document dependencies. # requirements_cfg.txt jinja2==2.6 markupsafe==0.15 (venv)% pip install -r requirements_cfg.txt

Python Libraries Use pip requirements files to install and document dependencies. # requirements_vnd.txt Flask==0.10 google-api-python-client (venv)% pip install -t lib \ r requirements_vnd.txt

Using Flask

Using Flask Install Flask in./lib Request jinja2 and markup safe in app.yaml; install in virtualenv lib/markupsafe s C-based speed-up is not usable but app.yaml will override with built-in app = Flask() No need to call app.run(); GAE dev server will take care of it

Cloud Datastore and ndb from google.appengine.ext import ndb class Entry(ndb.Model): title = ndb.stringproperty(required=true) text = ndb.textproperty(required=true) last_updated_date = ndb.datetimeproperty( auto_now=true)

Cloud Datastore and ndb entry = Entry( title=flask.request.form[ title ], text=flask.request.form[ text ]) entry.put() entries = Entry.query().order( -Entry.last_updated_date) for entry in entries: #...

Google Accounts from google.appengine.api import users user = users.get_current_user() if user: # user.nickname... login_url = users.create_login_url( / ) logout_url = users.create_logout_url( / )

Google Accounts # app.yaml handlers: - url: /add script: main.app login: required - url:.* script: main.app

Demo

Testing

Testing It s just Python, right? Activate your virtualenv Make sure google_appengine, the app root, and./lib are in PYTHONPATH (also yaml) Use your favorite test framework (e.g. unittest)

testbed Service API stubs for a clean test environment, including Cloud Datastore Provided by the GAE SDK google.appengine.ext.testbed Datastore: can fuzz test consistency guarantees Users: can set signed-in status, address, isadmin status

testbed import unittest from google.appengine.ext import testbed import main import models class MyBlogTestCase(unittest.TestCase): def setup(self): #... def teardown(self): #...

testbed class MyBlogTestCase(unittest.TestCase): def setup(self): self.tb = testbed.testbed() self.tb.activate() self.tb.init_datastore_v3_stub() self.tb.init_memcache_stub() self.tb.init_user_stub() main.app.config['testing'] = True self.app = main.app.test_client()

testbed class MyBlogTestCase(unittest.TestCase): def teardown(self): self.tb.deactivate()

testbed class TestEntry(MyBlogTestCase): def test_entry(self): m = models.entry( title='test', text='test entry text') m.put() self.assertisnotnone(m.last_updated_date)

testbed class MyBlogInteractions(MyBlogTestCase): def test_no_entries(self): rv = self.app.get('/') assert 'No entries here so far' in rv.data def test_one_entry(self): e = models.entry(title='test', text='test text') e.put() rv = self.app.get('/') assert 'No entries here so far' not in rv.data

testbed tb.init_all_stubs() tb.init_blobstore_stub() tb.init_datastore_v3_stub() tb.init_memcache_stub() tb.init_images_stub() tb.init_mail_stub() tb.init_taskqueue_stub() tb.init_urlfetch_stub() tb.init_user_stub() tb.init_xmpp_stub() cloud.google.com/appengine/docs/python/tools/ localunittesting

Flask Testing flask.pocoo.org/docs/0.10/testing/

Demo

Deploying, Monitoring, Debugging

Demo

Where to go from here Modules Task Queues Advanced Cloud Datastore: ndb, transactions, memcache Cloud SQL Cloud Storage Compute / Container Engine Managed VMs (beta)

Thank you! cloud.google.com ae-book.appspot.com Programming Google App Engine with Python, with Java Early Access / pre-order now Fully available June 2015 Dan Sanderson profiles.google.com/ dan.sanderson