Optimizing Your App Engine App

Similar documents
Getting the most out of Spring and App Engine!!

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

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

Developing Solutions for Google Cloud Platform (CPD200) Course Agenda

Scaling App Engine Applications. Justin Haugh, Guido van Rossum May 10, 2011

Building Scalable Web Apps with Google App Engine. Brett Slatkin June 14, 2008

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

Google GCP-Solution Architects Exam

Developing with Google App Engine

Western Michigan University

Goals. Facebook s Scaling Problem. Scaling Strategy. Facebook Three Layer Architecture. Workload. Memcache as a Service.


Improve Web Application Performance with Zend Platform

Cloud Computing Platform as a Service

CS 3510 Comp&Net Arch

CS 153 Design of Operating Systems Winter 2016

Deep Learning Inference as a Service

Cache memories are small, fast SRAM-based memories managed automatically in hardware. Hold frequently accessed blocks of main memory

Memory Hierarchy. Caching Chapter 7. Locality. Program Characteristics. What does that mean?!? Exploiting Spatial & Temporal Locality

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

Chapter 8. Virtual Memory

Lecture: Large Caches, Virtual Memory. Topics: cache innovations (Sections 2.4, B.4, B.5)

CS 261 Fall Caching. Mike Lam, Professor. (get it??)

Large-Scale Web Applications

Memory Hierarchy. 2/18/2016 CS 152 Sec6on 5 Colin Schmidt

Building scalable, complex apps on App Engine. Brett Slatkin May 27th, 2009

Lecture: Large Caches, Virtual Memory. Topics: cache innovations (Sections 2.4, B.4, B.5)

App Engine: Datastore Introduction

Memory hier ar hier ch ar y ch rev re i v e i w e ECE 154B Dmitri Struko Struk v o

Realtime visitor analysis with Couchbase and Elasticsearch

Caches. Samira Khan March 23, 2017

MEMORY. Objectives. L10 Memory

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 3: Caching (1) Welcome!

Be Fast, Cheap and in Control with SwitchKV Xiaozhou Li

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, 2016

Infiniswap. Efficient Memory Disaggregation. Mosharaf Chowdhury. with Juncheng Gu, Youngmoon Lee, Yiwen Zhang, and Kang G. Shin

CIT 668: System Architecture. Caching

I/O Buffering and Streaming

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

Introduction to OpenMP. Lecture 10: Caches

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

Agenda. EE 260: Introduction to Digital Design Memory. Naive Register File. Agenda. Memory Arrays: SRAM. Memory Arrays: Register File

Advanced Database Systems

Be Fast, Cheap and in Control with SwitchKV. Xiaozhou Li

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 3: Caching (1) Welcome!

Platform as a Service (PaaS)

AWS Lambda. 1.1 What is AWS Lambda?

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Memshare: a Dynamic Multi-tenant Key-value Cache

Key Point. What are Cache lines

Distributed Systems. 29. Distributed Caching Paul Krzyzanowski. Rutgers University. Fall 2014

Spotify Behind the Scenes

Backend Development. SWE 432, Fall Web Application Development

Four Components of a Computer System

Cray XE6 Performance Workshop

Microservices. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Lecture: Cache Hierarchies. Topics: cache innovations (Sections B.1-B.3, 2.1)

Locality. CS429: Computer Organization and Architecture. Locality Example 2. Locality Example

Tales of the Tail Hardware, OS, and Application-level Sources of Tail Latency

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

A Tracing Technique for Understanding the Behavior of Large-Scale Distributed Systems

Virtual Memory: From Address Translation to Demand Paging

Big and Fast. Anti-Caching in OLTP Systems. Justin DeBrabant

Algorithm Performance Factors. Memory Performance of Algorithms. Processor-Memory Performance Gap. Moore s Law. Program Model of Memory II

vmpooler pdxdevops : April 2015

Chapter 6 Memory 11/3/2015. Chapter 6 Objectives. 6.2 Types of Memory. 6.1 Introduction

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

Eleos: Exit-Less OS Services for SGX Enclaves

JBPM Course Content. Module-1 JBPM overview, Drools overview

Tips and Tricks: Designing low power Native and WebApps. Harita Chilukuri and Abhishek Dhanotia

Memory hierarchy review. ECE 154B Dmitri Strukov

A memcached implementation in Java. Bela Ban JBoss 2340

Caches 3/23/17. Agenda. The Dataflow Model (of a Computer)

Brief introduction of SocketPro continuous SQL-stream sending and processing system (Part 1: SQLite)

Announcements. ! Previous lecture. Caches. Inf3 Computer Architecture

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

Real World Web Scalability. Ask Bjørn Hansen Develooper LLC

Portland State University ECE 587/687. Caches and Memory-Level Parallelism

Algorithm Performance Factors. Memory Performance of Algorithms. Processor-Memory Performance Gap. Moore s Law. Program Model of Memory I

DATABASE SYSTEMS. Database programming in a web environment. Database System Course,

Overview IN this chapter we will study. William Stallings Computer Organization and Architecture 6th Edition

GAE Google App Engine

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Page 1. Multilevel Memories (Improving performance using a little cash )

Enabling Cost-effective Data Processing with Smart SSD

CMPSC 311- Introduction to Systems Programming Module: Caching

Parallel Python using the Multiprocess(ing) Package

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

VIRTUAL MEMORY II. Jo, Heeseung

Heimdall Data Access Platform Installation and Setup Guide

Cache Memories. From Bryant and O Hallaron, Computer Systems. A Programmer s Perspective. Chapter 6.

Lecture 17: Memory Hierarchy: Cache Design

Principles of Operating Systems

CS 153 Design of Operating Systems Winter 2016

ECE Lab 8. Logic Design for a Direct-Mapped Cache. To understand the function and design of a direct-mapped memory cache.

Lecture 8: Virtual Memory. Today: DRAM innovations, virtual memory (Sections )

Architecture: Caching Issues in Performance

DAT (cont d) Assume a page size of 256 bytes. physical addresses. Note: Virtual address (page #) is not stored, but is used as an index into the table

Cloud Programming. Programming Environment Oct 29, 2015 Osamu Tatebe

Architecture: Caching Issues in Performance

Transcription:

Optimizing Your App Engine App Marzia Niccolai Spender of GBucks Greg Darke Byte Herder Troy Trimble Professional Expert

Agenda Overview Writing applications efficiently Datastore Tips Caching, Caching, Caching Batch API requests Asynchronous workflows Offline workflows Performance Settings Future Work App Engine Servers

Overview

Latency vs. Cost Overview Latency vs Cost is a central tradeoff More efficient = lower costs More resources = higher costs Sometimes, you can reduce costs at the expense of speed

What is "Good Latency" Overview

Caveat Emptor Overview We're using Python here - but these strategies work well for Java too For things that only apply to one language, we'll let you know

Datastore Tips

Starting Out datastore tips General Strategies Minimizing calls per request Favor optimizing frequently viewed pages Migrate to HRD Specific Examples Use key ids/names Use run, not fetch (python) Use projection queries (for few properties) Use datastore cursors Use "embedded entities" to store structured data Set indexed=false

Datastore Anti-Design Pattern #1 datastore tips Don't do fetch(1):

Datastore Anti-Design Pattern #1 measurements Before 1 Datastore Fetch Op, 1 Datastore Query Op (2 Datastore Read Ops) 59 ms (as measured by AppStats) After 1 Datastore Fetch Op (1 Datastore Read Op) 4 ms (as measured by AppStats) Summary Costs 50% less and is 14x faster

Datastore Anti-Design Pattern #2 datastore tips In fact, in Python, don't use "fetch" at all, really:

Datastore Anti-Design Pattern #3 datastore tips When querying small entities, don't do this:

Datastore Anti-Design Pattern #3 measurements Before 1 Datastore Read Op (.07/100K ops) Full entity fetch (more bandwidth, longer latency) After 1 Datastore Small Ops (.01/100K ops) Only necessary fields Summary Costs 85% less

Datastore Anti-Design Pattern #4 datastore tips Don't use offsets:

Datastore Anti-Design Pattern #4 measurements Before 20 Datastore Fetch Ops, 1 Datastore Query Op (21 Datastore Read Ops) up to 177 ms (as measured by AppStats) After 10 Datastore Fetch Ops, 1 Datastore Query Op (11 Datastore Read Ops) 13 ms (as measured by AppStats) Summary Costs 47% less and is up to 13x faster

Datastore Design Pattern #1 datastore tips Embedded entities allow you to store structured data within a model Can be helpful for keep data denormalized for more efficient querying for a page

Datastore Design Pattern #2 datastore tips If a property of a model won't be used in a query, set that property to indexed=false When you write or update the entity you won't need to write any indexes for these properties

Caching, Caching, Caching

Memcache caching, caching, caching Place frequently used and slow to compute data in memcache

Instance Caching caching, caching, caching Allows you to have your own eviction policy for data Can be faster (memcache usually has around 2-5ms latency)

But, Really, Use NDB caching, caching, caching Making your caching algorithm correct is hard:

Datastore vs Memcache vs Instance Caching caching, caching, caching Datastore Memcache Instance Caching Latency 50+ ms 2-5 ms <1 ms Total Storage Unlimited (paid) Limited Limited; Instance Size Dependent Per Entity Storage 1 MB 1 MB Instance Size Dependent Eviction Policy User Managed LRU evicted User Managed/Instance Lifetime

Edge Caching caching, caching, caching

Batch API Requests

What are batch api requests? batch API requests Requests that operate on more than one piece of data Allows requests to 'fan out' to multiple servers Reduces overhead per piece of data

An example with Taskqueue Anti-pattern from google.appengine.api import taskqueue PY for i in xrange(50): taskqueue.add(name='offline-task-%d' % i, url='/my_offline_process', params={'value': 1}, countdown=i, queue_name='default')

An example with Taskqueue Using batch api from google.appengine.api import taskqueue PY queue = taskqueue.queue('default') tasks = [] for i in xrange(50): tasks.append(taskqueue.task(name='offline-task-%d' % i, url='/my_offline_process', params={'value': 1}, countdown=i)) queue.add(tasks)

APIs supporting batch api requests batch API requests API that supports batch calls: Memcache (get/set) Datastore (put/get/query) Taskqueue (add/lease_tasks) Full Text Search (index.add)

Asynchronous Workflows

Introduction to Asynchronisity Asynchronous workflows When to use: Perform 'slow' operations in parallel Perform cpu intensive operations while waiting for IO to complete

Asynchronous URLFetch Example Asynchronous workflows

Asynchronous URLFetch Example (using ndb tasklets) Asynchronous workflows

Asynchronous URLFetch Example Asynchronous workflows Before After

APIs with Asynchronous Methods Asynchronous workflows The following APIs have asynchronous methods available Blobstore (create_upload_url_async, delete_async) Memcache (set/get/delete-multi, incr/decr, more!) URLFetch Datastore

Move Work Offline

Taskqueues Move work offline If work can be deferred, then defer it Updating cached values Waiting for external services Also useful for workflow systems Perform fan in (Brett Slatkin, Google IO 2010: http://goo.gl/cagaa)

Taskqueues Using taskqueue to a slow external resource class UrlCache(ndb.Model): content = ndb.blobproperty(compressed=true) last_updated = ndb.datetimeproperty(indexed=false, auto_now=true) PY def _truncate_time(t, interval): return (t / interval) * interval def get_url(url): key_name = 'x' + hashlib.sha1(url).hexdigest() entry = UrlCache.get_by_id(key_name) if not entry: return update_cache(url, key_name).content if datetime.datetime.now() - entry.last_updated > datetime.timedelta(seconds=five_minutes): try: deferred.defer(update_cache, url, key_name, _name='urlcache-%s-%d' % (key_name, _truncate_time(time.time(), FIVE_MINUTES))) except (taskqueue.taskalreadyexistserror, taskqueue.tombstonedtaskerror): pass return entry.content def update_cache(url, key_name): entry = UrlCache(content=urlfetch.fetch(url).content, id=key_name) entry.put() return entry

Performance Settings

Performance Settings

Optimizing for Low Latency Performance Settings min_idle_instances Helps handle bursty traffic Avoids the dreaded Loading Request max_pending_latency Keep client latencies low

Optimizing for Low Latency Instances Console

Optimizing for Low Latency Performance Settings

PageSpeed Service Performance Settings

Optimizing for Low Cost Performance Settings max_idle_instances Keeps idle instances low to save money Affects 'Frontend Instance Hours' charge min_pending_latency Allows requests to wait longer for busy instances

Optimizing for Low Cost Performance Settings

Anti-Pattern Performance Settings Using Low Cost settings and Low Latency settings Don't do this!

App Engine Servers The Future...

Today's App Engine hierarchy Application Application Application Version Application Application Backend Version Version Instance Version Version Instance Version Version Instance Version Version Instance

Tomorrow's App Engine hierarchy Application Server Server Server Version Version Version Instance Instance Instance

App Engine Server Configuration Mobile Frontend Server application: myapp server: mobile-fe version: 1 runtime: python YAML server_settings: instance_class: F2 min_idle_instances: 25 max_idle_instances: automatic min_pending_latency: automatic max_pending_latency: 250ms handlers:...

App Engine Server Configuration Geo Backend Server application: myapp server: geo-be version: 1 runtime: java YAML server_settings: instances: 10 instance_class: B8 handlers:...

Recap... Marzia covered Datastore modeling patterns and antipatterns Greg talked about batch apis, asynchronous apis and offline requests Troy discussed optimization through Performance Settings and the new world of Servers to come

Thank You! Questions? Troy Trimble Marzia Niccolai Greg Darke