SlideShare ist ein Scribd-Unternehmen logo
1 von 62
Google App Engine performance tuning
David Chen from Tagtoo
Saturday, 1 June, 13
About me
• Tagtoo Cofounder & Senior Engineer
• NCTU Computer Science M.S.
• UW. Computational Finance M.S.
• Interested in:
• Python
• Google Cloud Platform
• Ski
• Taipei.py ROCK!
Saturday, 1 June, 13
Google App Engine & Google Cloud Platform
Saturday, 1 June, 13
Introduction
• Google App Engine in 2007
• PaaS (Platform as a Service)
• Total Solution
• Scalable, Easy to use (really?)
• Automatic scaling and loading balance
Saturday, 1 June, 13
Introduction
• Google App Engine in 2007
• PaaS (Platform as a Service)
• Total Solution
• Scalable, Easy to use (really?)
• Automatic scaling and loading balance
Hint:我要打十個
Saturday, 1 June, 13
Google Cloud Platform Family
https://cloud.google.com/
Saturday, 1 June, 13
Google Cloud Platform Family
• App Engine becomes gateway to
• Google Computing Engine (as EC2)
• CloudSQL (as MySQL)
• Big Query (SQL for terabyte)
• Cloud Storage
• 2013 Google I/O
• Datastore Service
• Php Support ...
Saturday, 1 June, 13
Why We Use App Engine
• Really Easy to configure
• Really Easy to scale
• Never Few Failed
• Fully Python environment
• Real Reason:
• Too Lazy to learn a complex platform
• Cheap / Powerful / Easy if use it carefully
Saturday, 1 June, 13
Why We Use App Engine
• Really Easy to configure
• Really Easy to scale
• Never Few Failed
• Fully Python environment
• Real Reason:
• Too Lazy to learn a complex platform
• Cheap / Powerful / Easy if use it carefully
Saturday, 1 June, 13
Performance Tuning
Saturday, 1 June, 13
Environment Configuration
• Python 2.7
• Thread: Safe
• High Replication Datastore (HRD)
• webapp2 + jinja2
https://developers.google.com/appengine/docs/adminconsole/performancesettings
Saturday, 1 June, 13
Setting
• Setting Frontend Instance Class
• Configure the Scheduler
• Idle Instance
• Pending Latency
• Task queue control
• X-AppEngine-FailFast
• Backend Instance
• Discount Instance Hour (40% off)
Super Easy to Scale
Saturday, 1 June, 13
Performance Tuning #1: Log Analysis, find out
which kind of request need to be optimize
Saturday, 1 June, 13
Log Analysis
Saturday, 1 June, 13
Log Analysis
Saturday, 1 June, 13
Log Analysis
Saturday, 1 June, 13
Log Analysis
Saturday, 1 June, 13
Log Analysis
Saturday, 1 June, 13
Analysis Log in Details
• Export logs
• appcfg.py request_logs myapp/ mylogs.txt
• options:
--num_days
--end_date
--serverity=[0-4]
• appcfg.py --num_days=1 --end_date=2013-05-22 request_logs myapp/
mylogs.txt
Saturday, 1 June, 13
Log Parser
• Sqlite:
http://google-app-engine-samples.googlecode.com/svn/trunk/logparser/
logparser.py
• BigQuery:
https://code.google.com/p/log2bq/
MapReduce -> CloudStorage -> BigQuery
• MySQL:
http://github/lucemia/log2sql.git
Saturday, 1 June, 13
Query
• select path, count(*) as freq, avg(cpm_usd) as avg_cost from log group by
path order by avg_cost desc limit 10
• select path, avg(ms), count(*) from log where group by path order by avg(ms)
desc limit 10
Saturday, 1 June, 13
Query
• select path, count(*) as freq, avg(cpm_usd) as avg_cost from log group by
path order by avg_cost desc limit 10
• select path, avg(ms), count(*) from log where group by path order by avg(ms)
desc limit 10
Saturday, 1 June, 13
Performance Tuning #2: AppStat, find out how to
optimize request
Saturday, 1 June, 13
AppStat
• Profiling the RPC (remote procedure call) performance of your application.
• Datastore
• Memcache
• Url Fetch
• Mail
• ...
• AppEngine Charge for RPC
https://developers.google.com/appengine/
docs/python/tools/appstats
Saturday, 1 June, 13
AppStat
• Profiling the RPC (remote procedure call) performance of your application.
• Datastore
• Memcache
• Url Fetch
• Mail
• ...
• AppEngine Charge for RPC
https://developers.google.com/appengine/
docs/python/tools/appstats
Saturday, 1 June, 13
Install App Stats
App.yaml
appengine_config.py
Saturday, 1 June, 13
Demo App Stat
Saturday, 1 June, 13
What AppStat can tell
• Is your application making unnecessary RPC calls?
• Should it be caching data instead of making repeated RPC calls to get the
same data?
• Will your application perform better if multiple requests are executed in
parallel rather than serially?
Saturday, 1 June, 13
Performance Tuning #3: optimize rpc
Saturday, 1 June, 13
Method 1: Batch RPC
Batch Version
Saturday, 1 June, 13
Example: Batch RPC
Hint: Batch as much as you can (less than 500)
Saturday, 1 June, 13
Example: Batch RPC
Hint: Some function support batch mode
Saturday, 1 June, 13
Method 2: Async RPC
Saturday, 1 June, 13
Example: Async RPC
Hint: Read async need to control the flow carefully. fire the rpc as soon as
possible, get the result as late as possible.
Saturday, 1 June, 13
Example: Async RPC
Hint: For write, always try async, or try batch + async
Saturday, 1 June, 13
Method 3: Cache RPC result
RPC
RPC
Cached Version
Write to CacheRead Cache
Return if cache exists
Saturday, 1 June, 13
Example: Cache RPC
Hint: cache repeat rpc, check the hit ratio at Memcache Viewer
Saturday, 1 June, 13
Example: Cache RPC
Hint: memcache accept both async and batch operation
Saturday, 1 June, 13
Performance Tuning #4: optimize datastore
Saturday, 1 June, 13
Google App Engine Datastore
• Schemaless (NoSql) for large scale
• Need to manually configure index
• Support limited SQL command, but have different behavior
• offset
• No inequality on more than one property
• ...
• Support MapReduce (but expansive..)
Saturday, 1 June, 13
Datastore Index
• 太長了.. 有機會再講
Saturday, 1 June, 13
Datastore Pricing
• Write: 50000 free, $0.1 / 100k
Read: 50000 free, $0.07 / 100k
Small: 50000 free, $0.01 / 100k
• Looks Fine?
• In fact:
• Write could be much more expansive than you expected
Saturday, 1 June, 13
Datastore Pricing
Saturday, 1 June, 13
Datastore Pricing
Saturday, 1 June, 13
Datastore Pricing
Saturday, 1 June, 13
SAMPLE
• Get:
1 read ops = $0.07 / 100k
• Insert:
2 + 2 x 12 = 26 write ops = $2.6 / 100k
Hint: Each index property cost money
Saturday, 1 June, 13
SAMPLE
• Get:
1 read ops = $0.07 / 100k
• Insert:
2 + 2 x 12 = 26 write ops = $2.6 / 100k 37x
Hint: Each index property cost money
Saturday, 1 June, 13
How to optimize it?
Saturday, 1 June, 13
Redefined Model with “indexed=False”
• Get:
1 read ops = $0.07 / 100k
• Insert:
2 = 2 write ops = $0.2 / 100k
• Cannot query with property
with indexed=False
2x
Hint: know how you wanna query your data
before define the model
Saturday, 1 June, 13
ListProperty
Hint: ListProperty is useful, but could also be dangerous
Saturday, 1 June, 13
ListProperty + MapReduce
Hint: MapReduce + ListProperty could be more than dangerous...
Saturday, 1 June, 13
Entity Size
Hint: Entity size won’t affect the cost (and won’t affect the performance)
Saturday, 1 June, 13
Datastore Hints
• Make Table BIG!
• but only index if it is necessary
• Find Alternative Solution:
• CloudSQL + Cache
• query index and tree in memory
Saturday, 1 June, 13
Build index
https://code.google.com/p/google-app-engine-ranklist/
Hint: Binary Tree, Trie, etc.. Build complex data structure
Saturday, 1 June, 13
More Design Principle
• Denormalize is better than normalize
• Think about real user case
• MxM or Mxn or nxn?
• More read or more write?
• immutable data?
• relation or duplicate?
• Get or Query?
• ...
Zen of datastore
Saturday, 1 June, 13
Google App Engine - NDB
• Automatic caching
• In-Context Cache
• write through - Memcache Cache
• The StructuredProperty class, which allows entities to have nested structure
• Asynchronous APIs which allow concurrent actions (and "synchronous" APIs
if you don't need that)
• Watch Out: Different Async Behavior
Hint: use ndb
Saturday, 1 June, 13
Performance Tuning #5: optimize control
Datastore RenderLogic
Saturday, 1 June, 13
Use server side cache
Datastore RenderLogic
Update Cache
Return if cache exists
Saturday, 1 June, 13
Use server side cache
Datastore RenderLogic
Update Cache
Return if cache exists
Saturday, 1 June, 13
Use server side cache
Datastore RenderLogic
Update Cache
Return if cache exists
Saturday, 1 June, 13
Use Tasks for non-request bound functionality
• Offline Update
•
Datastore RenderLogic
Saturday, 1 June, 13
Host dynamic content as static
• Last-Modified, ETag
• Expires, max-age
• Expires
• Edge-Control
Saturday, 1 June, 13

Weitere ähnliche Inhalte

Was ist angesagt?

Presto anatomy
Presto anatomyPresto anatomy
Presto anatomyDongmin Yu
 
HadoopCon 2016 - 用 Jupyter Notebook Hold 住一個上線 Spark Machine Learning 專案實戰
HadoopCon 2016  - 用 Jupyter Notebook Hold 住一個上線 Spark  Machine Learning 專案實戰HadoopCon 2016  - 用 Jupyter Notebook Hold 住一個上線 Spark  Machine Learning 專案實戰
HadoopCon 2016 - 用 Jupyter Notebook Hold 住一個上線 Spark Machine Learning 專案實戰Wayne Chen
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleKaty Slemon
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 
Luigi presentation OA Summit
Luigi presentation OA SummitLuigi presentation OA Summit
Luigi presentation OA SummitOpen Analytics
 
The Modern Java Web Developer Bootcamp - Devoxx 2013
The Modern Java Web Developer Bootcamp - Devoxx 2013The Modern Java Web Developer Bootcamp - Devoxx 2013
The Modern Java Web Developer Bootcamp - Devoxx 2013Matt Raible
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGuillaume Laforge
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsAtlassian
 
Debugging Apache Spark - Scala & Python super happy fun times 2017
Debugging Apache Spark -   Scala & Python super happy fun times 2017Debugging Apache Spark -   Scala & Python super happy fun times 2017
Debugging Apache Spark - Scala & Python super happy fun times 2017Holden Karau
 
Monitoring Spark Applications
Monitoring Spark ApplicationsMonitoring Spark Applications
Monitoring Spark ApplicationsTzach Zohar
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gearsdion
 
Debugging PySpark: Spark Summit East talk by Holden Karau
Debugging PySpark: Spark Summit East talk by Holden KarauDebugging PySpark: Spark Summit East talk by Holden Karau
Debugging PySpark: Spark Summit East talk by Holden KarauSpark Summit
 
Scala in hulu's data platform
Scala in hulu's data platformScala in hulu's data platform
Scala in hulu's data platformPrasan Samtani
 
Beyond Wordcount with spark datasets (and scalaing) - Nide PDX Jan 2018
Beyond Wordcount  with spark datasets (and scalaing) - Nide PDX Jan 2018Beyond Wordcount  with spark datasets (and scalaing) - Nide PDX Jan 2018
Beyond Wordcount with spark datasets (and scalaing) - Nide PDX Jan 2018Holden Karau
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
 

Was ist angesagt? (20)

Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
Making KVS 10x Scalable
Making KVS 10x ScalableMaking KVS 10x Scalable
Making KVS 10x Scalable
 
HadoopCon 2016 - 用 Jupyter Notebook Hold 住一個上線 Spark Machine Learning 專案實戰
HadoopCon 2016  - 用 Jupyter Notebook Hold 住一個上線 Spark  Machine Learning 專案實戰HadoopCon 2016  - 用 Jupyter Notebook Hold 住一個上線 Spark  Machine Learning 專案實戰
HadoopCon 2016 - 用 Jupyter Notebook Hold 住一個上線 Spark Machine Learning 專案實戰
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 
Luigi presentation OA Summit
Luigi presentation OA SummitLuigi presentation OA Summit
Luigi presentation OA Summit
 
Om nom nom nom
Om nom nom nomOm nom nom nom
Om nom nom nom
 
The Modern Java Web Developer Bootcamp - Devoxx 2013
The Modern Java Web Developer Bootcamp - Devoxx 2013The Modern Java Web Developer Bootcamp - Devoxx 2013
The Modern Java Web Developer Bootcamp - Devoxx 2013
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Tips for Angular Applications
Tips for Angular ApplicationsTips for Angular Applications
Tips for Angular Applications
 
Building a spa_in_30min
Building a spa_in_30minBuilding a spa_in_30min
Building a spa_in_30min
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian Plugins
 
Debugging Apache Spark - Scala & Python super happy fun times 2017
Debugging Apache Spark -   Scala & Python super happy fun times 2017Debugging Apache Spark -   Scala & Python super happy fun times 2017
Debugging Apache Spark - Scala & Python super happy fun times 2017
 
Monitoring Spark Applications
Monitoring Spark ApplicationsMonitoring Spark Applications
Monitoring Spark Applications
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Debugging PySpark: Spark Summit East talk by Holden Karau
Debugging PySpark: Spark Summit East talk by Holden KarauDebugging PySpark: Spark Summit East talk by Holden Karau
Debugging PySpark: Spark Summit East talk by Holden Karau
 
Scala in hulu's data platform
Scala in hulu's data platformScala in hulu's data platform
Scala in hulu's data platform
 
Beyond Wordcount with spark datasets (and scalaing) - Nide PDX Jan 2018
Beyond Wordcount  with spark datasets (and scalaing) - Nide PDX Jan 2018Beyond Wordcount  with spark datasets (and scalaing) - Nide PDX Jan 2018
Beyond Wordcount with spark datasets (and scalaing) - Nide PDX Jan 2018
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 

Ähnlich wie AppEngine Performance Tuning

Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby ConferenceJohn Woodell
 
Does Your Stuff Scale?
Does Your Stuff Scale?Does Your Stuff Scale?
Does Your Stuff Scale?stevenh0lmes
 
Proud to be polyglot!
Proud to be polyglot!Proud to be polyglot!
Proud to be polyglot!NLJUG
 
In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)
In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)
In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)Mark Rittman
 
Apereo OAE - Architectural overview
Apereo OAE - Architectural overviewApereo OAE - Architectural overview
Apereo OAE - Architectural overviewNicolaas Matthijs
 
Agile analytics applications on hadoop
Agile analytics applications on hadoopAgile analytics applications on hadoop
Agile analytics applications on hadoopRussell Jurney
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureDAGEOP LTD
 
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...Big Data Spain
 
Multi dimension aggregations using spark and dataframes
Multi dimension aggregations using spark and dataframesMulti dimension aggregations using spark and dataframes
Multi dimension aggregations using spark and dataframesRomi Kuntsman
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009John Woodell
 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationAtlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationGunnar Hillert
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsAchievers Tech
 
Indextank east bay ruby meetup slides
Indextank east bay ruby meetup slidesIndextank east bay ruby meetup slides
Indextank east bay ruby meetup slidesYogiWanKenobi
 
Benchmarking at Parse
Benchmarking at ParseBenchmarking at Parse
Benchmarking at ParseTravis Redman
 
Advanced Benchmarking at Parse
Advanced Benchmarking at ParseAdvanced Benchmarking at Parse
Advanced Benchmarking at ParseMongoDB
 
Tops for Lean Startup
Tops for Lean StartupTops for Lean Startup
Tops for Lean StartupDavid Chen
 
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013Amazon Web Services
 
Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Kate Marshalkina
 

Ähnlich wie AppEngine Performance Tuning (20)

App Engine Meetup
App Engine MeetupApp Engine Meetup
App Engine Meetup
 
Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby Conference
 
Does Your Stuff Scale?
Does Your Stuff Scale?Does Your Stuff Scale?
Does Your Stuff Scale?
 
Proud to be polyglot!
Proud to be polyglot!Proud to be polyglot!
Proud to be polyglot!
 
In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)
In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)
In-Memory Oracle BI Applications (UKOUG Analytics Event, July 2013)
 
Apereo OAE - Architectural overview
Apereo OAE - Architectural overviewApereo OAE - Architectural overview
Apereo OAE - Architectural overview
 
Agile analytics applications on hadoop
Agile analytics applications on hadoopAgile analytics applications on hadoop
Agile analytics applications on hadoop
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser Architecture
 
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
 
Treasure Data Cloud Strategy
Treasure Data Cloud StrategyTreasure Data Cloud Strategy
Treasure Data Cloud Strategy
 
Multi dimension aggregations using spark and dataframes
Multi dimension aggregations using spark and dataframesMulti dimension aggregations using spark and dataframes
Multi dimension aggregations using spark and dataframes
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009
 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationAtlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring Integration
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty Details
 
Indextank east bay ruby meetup slides
Indextank east bay ruby meetup slidesIndextank east bay ruby meetup slides
Indextank east bay ruby meetup slides
 
Benchmarking at Parse
Benchmarking at ParseBenchmarking at Parse
Benchmarking at Parse
 
Advanced Benchmarking at Parse
Advanced Benchmarking at ParseAdvanced Benchmarking at Parse
Advanced Benchmarking at Parse
 
Tops for Lean Startup
Tops for Lean StartupTops for Lean Startup
Tops for Lean Startup
 
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
 
Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014
 

Mehr von David Chen

Build Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 TaiwanBuild Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 TaiwanDavid Chen
 
python small tools for CI and team cooperation
python small tools for CI and team cooperationpython small tools for CI and team cooperation
python small tools for CI and team cooperationDavid Chen
 
Case study of Google Cloud Platform
Case study of Google Cloud PlatformCase study of Google Cloud Platform
Case study of Google Cloud PlatformDavid Chen
 
Talk in Google fest 2013
Talk in Google fest 2013Talk in Google fest 2013
Talk in Google fest 2013David Chen
 
doT.py - a python template engine.
doT.py - a python template engine.doT.py - a python template engine.
doT.py - a python template engine.David Chen
 
Final presentation for mobile strategy
Final presentation for mobile strategyFinal presentation for mobile strategy
Final presentation for mobile strategyDavid Chen
 
Gam Documentation
Gam DocumentationGam Documentation
Gam DocumentationDavid Chen
 
Gam Documentation
Gam DocumentationGam Documentation
Gam DocumentationDavid Chen
 

Mehr von David Chen (11)

Build Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 TaiwanBuild Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 Taiwan
 
python small tools for CI and team cooperation
python small tools for CI and team cooperationpython small tools for CI and team cooperation
python small tools for CI and team cooperation
 
Big datalab
Big datalabBig datalab
Big datalab
 
Case study of Google Cloud Platform
Case study of Google Cloud PlatformCase study of Google Cloud Platform
Case study of Google Cloud Platform
 
Talk in Google fest 2013
Talk in Google fest 2013Talk in Google fest 2013
Talk in Google fest 2013
 
doT.py - a python template engine.
doT.py - a python template engine.doT.py - a python template engine.
doT.py - a python template engine.
 
Final presentation for mobile strategy
Final presentation for mobile strategyFinal presentation for mobile strategy
Final presentation for mobile strategy
 
長庚大學
長庚大學長庚大學
長庚大學
 
GAM Slide
GAM SlideGAM Slide
GAM Slide
 
Gam Documentation
Gam DocumentationGam Documentation
Gam Documentation
 
Gam Documentation
Gam DocumentationGam Documentation
Gam Documentation
 

Kürzlich hochgeladen

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Kürzlich hochgeladen (20)

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

AppEngine Performance Tuning

  • 1. Google App Engine performance tuning David Chen from Tagtoo Saturday, 1 June, 13
  • 2. About me • Tagtoo Cofounder & Senior Engineer • NCTU Computer Science M.S. • UW. Computational Finance M.S. • Interested in: • Python • Google Cloud Platform • Ski • Taipei.py ROCK! Saturday, 1 June, 13
  • 3. Google App Engine & Google Cloud Platform Saturday, 1 June, 13
  • 4. Introduction • Google App Engine in 2007 • PaaS (Platform as a Service) • Total Solution • Scalable, Easy to use (really?) • Automatic scaling and loading balance Saturday, 1 June, 13
  • 5. Introduction • Google App Engine in 2007 • PaaS (Platform as a Service) • Total Solution • Scalable, Easy to use (really?) • Automatic scaling and loading balance Hint:我要打十個 Saturday, 1 June, 13
  • 6. Google Cloud Platform Family https://cloud.google.com/ Saturday, 1 June, 13
  • 7. Google Cloud Platform Family • App Engine becomes gateway to • Google Computing Engine (as EC2) • CloudSQL (as MySQL) • Big Query (SQL for terabyte) • Cloud Storage • 2013 Google I/O • Datastore Service • Php Support ... Saturday, 1 June, 13
  • 8. Why We Use App Engine • Really Easy to configure • Really Easy to scale • Never Few Failed • Fully Python environment • Real Reason: • Too Lazy to learn a complex platform • Cheap / Powerful / Easy if use it carefully Saturday, 1 June, 13
  • 9. Why We Use App Engine • Really Easy to configure • Really Easy to scale • Never Few Failed • Fully Python environment • Real Reason: • Too Lazy to learn a complex platform • Cheap / Powerful / Easy if use it carefully Saturday, 1 June, 13
  • 11. Environment Configuration • Python 2.7 • Thread: Safe • High Replication Datastore (HRD) • webapp2 + jinja2 https://developers.google.com/appengine/docs/adminconsole/performancesettings Saturday, 1 June, 13
  • 12. Setting • Setting Frontend Instance Class • Configure the Scheduler • Idle Instance • Pending Latency • Task queue control • X-AppEngine-FailFast • Backend Instance • Discount Instance Hour (40% off) Super Easy to Scale Saturday, 1 June, 13
  • 13. Performance Tuning #1: Log Analysis, find out which kind of request need to be optimize Saturday, 1 June, 13
  • 19. Analysis Log in Details • Export logs • appcfg.py request_logs myapp/ mylogs.txt • options: --num_days --end_date --serverity=[0-4] • appcfg.py --num_days=1 --end_date=2013-05-22 request_logs myapp/ mylogs.txt Saturday, 1 June, 13
  • 20. Log Parser • Sqlite: http://google-app-engine-samples.googlecode.com/svn/trunk/logparser/ logparser.py • BigQuery: https://code.google.com/p/log2bq/ MapReduce -> CloudStorage -> BigQuery • MySQL: http://github/lucemia/log2sql.git Saturday, 1 June, 13
  • 21. Query • select path, count(*) as freq, avg(cpm_usd) as avg_cost from log group by path order by avg_cost desc limit 10 • select path, avg(ms), count(*) from log where group by path order by avg(ms) desc limit 10 Saturday, 1 June, 13
  • 22. Query • select path, count(*) as freq, avg(cpm_usd) as avg_cost from log group by path order by avg_cost desc limit 10 • select path, avg(ms), count(*) from log where group by path order by avg(ms) desc limit 10 Saturday, 1 June, 13
  • 23. Performance Tuning #2: AppStat, find out how to optimize request Saturday, 1 June, 13
  • 24. AppStat • Profiling the RPC (remote procedure call) performance of your application. • Datastore • Memcache • Url Fetch • Mail • ... • AppEngine Charge for RPC https://developers.google.com/appengine/ docs/python/tools/appstats Saturday, 1 June, 13
  • 25. AppStat • Profiling the RPC (remote procedure call) performance of your application. • Datastore • Memcache • Url Fetch • Mail • ... • AppEngine Charge for RPC https://developers.google.com/appengine/ docs/python/tools/appstats Saturday, 1 June, 13
  • 28. What AppStat can tell • Is your application making unnecessary RPC calls? • Should it be caching data instead of making repeated RPC calls to get the same data? • Will your application perform better if multiple requests are executed in parallel rather than serially? Saturday, 1 June, 13
  • 29. Performance Tuning #3: optimize rpc Saturday, 1 June, 13
  • 30. Method 1: Batch RPC Batch Version Saturday, 1 June, 13
  • 31. Example: Batch RPC Hint: Batch as much as you can (less than 500) Saturday, 1 June, 13
  • 32. Example: Batch RPC Hint: Some function support batch mode Saturday, 1 June, 13
  • 33. Method 2: Async RPC Saturday, 1 June, 13
  • 34. Example: Async RPC Hint: Read async need to control the flow carefully. fire the rpc as soon as possible, get the result as late as possible. Saturday, 1 June, 13
  • 35. Example: Async RPC Hint: For write, always try async, or try batch + async Saturday, 1 June, 13
  • 36. Method 3: Cache RPC result RPC RPC Cached Version Write to CacheRead Cache Return if cache exists Saturday, 1 June, 13
  • 37. Example: Cache RPC Hint: cache repeat rpc, check the hit ratio at Memcache Viewer Saturday, 1 June, 13
  • 38. Example: Cache RPC Hint: memcache accept both async and batch operation Saturday, 1 June, 13
  • 39. Performance Tuning #4: optimize datastore Saturday, 1 June, 13
  • 40. Google App Engine Datastore • Schemaless (NoSql) for large scale • Need to manually configure index • Support limited SQL command, but have different behavior • offset • No inequality on more than one property • ... • Support MapReduce (but expansive..) Saturday, 1 June, 13
  • 41. Datastore Index • 太長了.. 有機會再講 Saturday, 1 June, 13
  • 42. Datastore Pricing • Write: 50000 free, $0.1 / 100k Read: 50000 free, $0.07 / 100k Small: 50000 free, $0.01 / 100k • Looks Fine? • In fact: • Write could be much more expansive than you expected Saturday, 1 June, 13
  • 46. SAMPLE • Get: 1 read ops = $0.07 / 100k • Insert: 2 + 2 x 12 = 26 write ops = $2.6 / 100k Hint: Each index property cost money Saturday, 1 June, 13
  • 47. SAMPLE • Get: 1 read ops = $0.07 / 100k • Insert: 2 + 2 x 12 = 26 write ops = $2.6 / 100k 37x Hint: Each index property cost money Saturday, 1 June, 13
  • 48. How to optimize it? Saturday, 1 June, 13
  • 49. Redefined Model with “indexed=False” • Get: 1 read ops = $0.07 / 100k • Insert: 2 = 2 write ops = $0.2 / 100k • Cannot query with property with indexed=False 2x Hint: know how you wanna query your data before define the model Saturday, 1 June, 13
  • 50. ListProperty Hint: ListProperty is useful, but could also be dangerous Saturday, 1 June, 13
  • 51. ListProperty + MapReduce Hint: MapReduce + ListProperty could be more than dangerous... Saturday, 1 June, 13
  • 52. Entity Size Hint: Entity size won’t affect the cost (and won’t affect the performance) Saturday, 1 June, 13
  • 53. Datastore Hints • Make Table BIG! • but only index if it is necessary • Find Alternative Solution: • CloudSQL + Cache • query index and tree in memory Saturday, 1 June, 13
  • 54. Build index https://code.google.com/p/google-app-engine-ranklist/ Hint: Binary Tree, Trie, etc.. Build complex data structure Saturday, 1 June, 13
  • 55. More Design Principle • Denormalize is better than normalize • Think about real user case • MxM or Mxn or nxn? • More read or more write? • immutable data? • relation or duplicate? • Get or Query? • ... Zen of datastore Saturday, 1 June, 13
  • 56. Google App Engine - NDB • Automatic caching • In-Context Cache • write through - Memcache Cache • The StructuredProperty class, which allows entities to have nested structure • Asynchronous APIs which allow concurrent actions (and "synchronous" APIs if you don't need that) • Watch Out: Different Async Behavior Hint: use ndb Saturday, 1 June, 13
  • 57. Performance Tuning #5: optimize control Datastore RenderLogic Saturday, 1 June, 13
  • 58. Use server side cache Datastore RenderLogic Update Cache Return if cache exists Saturday, 1 June, 13
  • 59. Use server side cache Datastore RenderLogic Update Cache Return if cache exists Saturday, 1 June, 13
  • 60. Use server side cache Datastore RenderLogic Update Cache Return if cache exists Saturday, 1 June, 13
  • 61. Use Tasks for non-request bound functionality • Offline Update • Datastore RenderLogic Saturday, 1 June, 13
  • 62. Host dynamic content as static • Last-Modified, ETag • Expires, max-age • Expires • Edge-Control Saturday, 1 June, 13