SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
I’ve (probably) been using

Google App Engine
     for a week longer than you have

Simon Willison - http://simonwillison.net/
BarCamp London 4
31st May 2008
Except you have to re-write
     your whole application
If you totally rethink the
 way you use a database
What it can do
• Serve static files
• Serve dynamic requests
• Store data
• Call web services (sort of)
• Authenticate against Google’s user database
• Send e-mail, process images, use memcache
The dev environment
                    is really, really nice


•   Download the (open source) SDK

    •   a full simulation of the App Engine environment

•   dev_appserver.py myapp     for a local webserver

•   appcfg.py update myapp     to deploy to the cloud
Options
• You have to use Python
• You can choose how you use it:
 • CGI-style scripts
 • WSGI applications
 • Google’s webapp framework
 • Django (0.96 provided, or install your own)
Hello World
# helloworld.py
print quot;Content-Type: text/htmlquot;
print
print quot;Hello, world!quot;

# app.yaml
application: simonwillison-helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: helloworld.py
With webapp and WSGI
import wsgiref.handlers
from google.appengine.ext import webapp

class MainPage(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/html'
    self.response.out.write('Hello, webapp World!')

def main():
  application = webapp.WSGIApplication(
    [('/', MainPage)], debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == quot;__main__quot;:
  main()
With Django
from django.conf.urls.defaults import *
from django.http import HttpResponse

def hello(request):
    return HttpResponse(quot;Hello, World!quot;)

urlpatterns = patterns('',
    ('^$', hello),
)

(And django_dispatch.py for boilerplate)
•   Don't use CGI: it requires reloading for every hit

•   Why use Django over webapp?

    •   Django has easy cookies and custom 500 errors

    •   Django is less verbose

    •   Django middleware is really handy

•   You can use other WSGI frameworks if you like
Static files
# in app.yaml

handlers:
- url: /css
  static_dir: css
- url: /img
  static_dir: img
- url: /favicon.ico
  static_files: img/favicon.ico
  upload: img/favicon.ico
  mime_type: image/x-icon
The Datastore API
“Bigtable is a distributed storage system for
 managing structured data that is designed
  to scale to a very large size: petabytes of
    data across thousands of commodity
servers. Many projects at Google store data
 in Bigtable, including web indexing, Google
         Earth, and Google Finance.”
The App Engine datastore
• Apparently based on BigTable
• Absolutely not a relational database
 • No joins (they do have “reference fields”)
 • No aggregate queries - not even count()!
 • Hierarchy affects sharding and transactions
• All queries must run against an existing index
Models and entities
• Data is stored as entities
 • Entities have properties - key/value pairs
 • An entity has a unique key
• Entities live in a hierarchy, and siblings exist in
  the same entity group - these are actually really
  important for transactions and performance
• A model is kind of like a class; it lets you define
  a type of entity
AppEngine Models
   from google.appengine.ext import db

   class Account(db.Model):
     slug = db.StringProperty(required=True)
     owner = db.UserProperty()
     onlyme = db.BooleanProperty()
     referrers = db.StringListProperty()

(There is a ReferenceProperty, but I haven’t used it yet)
Inserting data
account = Account(
    key_name = slug,
    slug = slug,
    referrers = ['...', '...'],
    onlyme = False,
    owner = users.get_current_user()
)
db.put(account) # Or account.put()

Browser.get_or_insert(key_name,
    parent = account,
    slug = browser_slug
)
Running queries

Browser.all().ancestor(account)

Account.gql(quot;WHERE slug = :1quot;, slug))

Story.all().filter(
  'title =', 'Foo'
).order('-date')
BUT...
•   All queries must run against an existing index

•   Filtering or sorting on a property requires that
    the property exists

•   Inequality filters are allowed on one property only

•   Properties in inequality filters must be sorted
    before other sort orders

•   ... and various other rules

•   Thankfully the dev server creates most indexes
    for you automatically based on usage
How indexes are used
1. The datastore identifies the index that
  corresponds with the query’s kind, filter
  properties, filter operators, and sort orders.
2. The datastore starts scanning the index at the
  first entity that meets all of the filter conditions
  using the query’s filter values.
3. The datastore continues to scan the index,
  returning each entity, until it finds the next entity
  that does not meet the filter conditions, or until
  it reaches the end of the index.
Further limitations
• If you create a new index and push it live,
  you have to wait for it to rebuilt
  • This can take hours, and apparently can go
    wrong
• You can’t safely grab more than about 500
  records at once - App Engine times out
• You can’t delete in bulk
Other random notes
•   You have to use the URL Fetch API to do
    HTTP requests (e.g. for web services) - and it
    times out agressively at about 5 seconds
•   The Google accounts Users API is ridiculously
    easy to use, but...
    •   no permanent unique identifier; if the user
        changes their e-mail address you’re screwed
•   The new image and memcache APIs are neat
Final thoughts
• It’s really nice not to have to worry about hosting
• But... the lack of aggregate queries and ad-hoc
  queries really hurts
• Perfect for small projects you don’t want to
  worry about and big things which you’re sure will
  have to scale
• Pricing is comparable to S3 - i.e. stupidly cheap
Pricing

• $0.10 - $0.12 per CPU core-hour
• $0.15 - $0.18 per GB-month of storage
• $0.11 - $0.13 per GB outgoing bandwidth
• $0.09 - $0.11 per GB incoming bandwidth
Thank you!

Más contenido relacionado

La actualidad más candente

Platform as a service google app engine
Platform as a service   google app enginePlatform as a service   google app engine
Platform as a service google app engine
Deepu S Nath
 
Google app engine - Overview
Google app engine - OverviewGoogle app engine - Overview
Google app engine - Overview
Nathan Quach
 

La actualidad más candente (20)

Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Platform as a service google app engine
Platform as a service   google app enginePlatform as a service   google app engine
Platform as a service google app engine
 
Google App Engine: An Introduction
Google App Engine: An IntroductionGoogle App Engine: An Introduction
Google App Engine: An Introduction
 
Developing Java Web Applications In Google App Engine
Developing Java Web Applications In Google App EngineDeveloping Java Web Applications In Google App Engine
Developing Java Web Applications In Google App Engine
 
Gentle App Engine Intro
Gentle App Engine IntroGentle App Engine Intro
Gentle App Engine Intro
 
What is Google App Engine?
What is Google App Engine?What is Google App Engine?
What is Google App Engine?
 
Google Application Engine
Google Application EngineGoogle Application Engine
Google Application Engine
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Google app engine - Overview
Google app engine - OverviewGoogle app engine - Overview
Google app engine - Overview
 
Google App engine
Google App engineGoogle App engine
Google App engine
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
App Engine
App EngineApp Engine
App Engine
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Google App Engine Introduction
Google App Engine IntroductionGoogle App Engine Introduction
Google App Engine Introduction
 
Google App Engine - Overview #3
Google App Engine - Overview #3Google App Engine - Overview #3
Google App Engine - Overview #3
 
Google App Engine (Introduction)
Google App Engine (Introduction)Google App Engine (Introduction)
Google App Engine (Introduction)
 
Powering your Apps via Google Cloud Platform
Powering your Apps via Google Cloud PlatformPowering your Apps via Google Cloud Platform
Powering your Apps via Google Cloud Platform
 
Google Cloud Platform Updates
Google Cloud Platform UpdatesGoogle Cloud Platform Updates
Google Cloud Platform Updates
 

Destacado

Bigtable: A Distributed Storage System for Structured Data
Bigtable: A Distributed Storage System for Structured DataBigtable: A Distributed Storage System for Structured Data
Bigtable: A Distributed Storage System for Structured Data
elliando dias
 

Destacado (16)

Big table
Big tableBig table
Big table
 
ROCKING YOUR SEAT AT THE BIG TABLE - ROB BAILEY
ROCKING YOUR SEAT AT THE BIG TABLE - ROB BAILEYROCKING YOUR SEAT AT THE BIG TABLE - ROB BAILEY
ROCKING YOUR SEAT AT THE BIG TABLE - ROB BAILEY
 
Google's BigTable
Google's BigTableGoogle's BigTable
Google's BigTable
 
Bigtable
BigtableBigtable
Bigtable
 
google Bigtable
google Bigtablegoogle Bigtable
google Bigtable
 
Google Bigtable Paper Presentation
Google Bigtable Paper PresentationGoogle Bigtable Paper Presentation
Google Bigtable Paper Presentation
 
Big table
Big tableBig table
Big table
 
GOOGLE BIGTABLE
GOOGLE BIGTABLEGOOGLE BIGTABLE
GOOGLE BIGTABLE
 
Bigtable
BigtableBigtable
Bigtable
 
Big table
Big tableBig table
Big table
 
Bigtable
BigtableBigtable
Bigtable
 
Bigtable: A Distributed Storage System for Structured Data
Bigtable: A Distributed Storage System for Structured DataBigtable: A Distributed Storage System for Structured Data
Bigtable: A Distributed Storage System for Structured Data
 
Google Big Table
Google Big TableGoogle Big Table
Google Big Table
 
Google Bigtable paper presentation
Google Bigtable paper presentationGoogle Bigtable paper presentation
Google Bigtable paper presentation
 
Google BigTable
Google BigTableGoogle BigTable
Google BigTable
 
The Google Bigtable
The Google BigtableThe Google Bigtable
The Google Bigtable
 

Similar a I've (probably) been using Google App Engine for a week longer than you have

iPhone Development For Experienced Web Developers
iPhone Development For Experienced Web DevelopersiPhone Development For Experienced Web Developers
iPhone Development For Experienced Web Developers
lisab517
 
Introduction to App Engine Development
Introduction to App Engine DevelopmentIntroduction to App Engine Development
Introduction to App Engine Development
Ron Reiter
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 

Similar a I've (probably) been using Google App Engine for a week longer than you have (20)

App Engine On Air: Munich
App Engine On Air: MunichApp Engine On Air: Munich
App Engine On Air: Munich
 
Castles in the Cloud: Developing with Google App Engine
Castles in the Cloud: Developing with Google App EngineCastles in the Cloud: Developing with Google App Engine
Castles in the Cloud: Developing with Google App Engine
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
Angularjs
AngularjsAngularjs
Angularjs
 
Gae
GaeGae
Gae
 
iPhone Development For Experienced Web Developers
iPhone Development For Experienced Web DevelopersiPhone Development For Experienced Web Developers
iPhone Development For Experienced Web Developers
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web Components
 
Introduction to App Engine Development
Introduction to App Engine DevelopmentIntroduction to App Engine Development
Introduction to App Engine Development
 
Google App Engine tutorial
Google App Engine tutorialGoogle App Engine tutorial
Google App Engine tutorial
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
 
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
"Progressive Web Apps" by Riza Fahmi	(Hacktiv8)"Progressive Web Apps" by Riza Fahmi	(Hacktiv8)
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
 
Progressive Web Apps. What, why and how
Progressive Web Apps. What, why and howProgressive Web Apps. What, why and how
Progressive Web Apps. What, why and how
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Google Cloud Developer Challenge - GDG Belgaum
Google Cloud Developer Challenge - GDG BelgaumGoogle Cloud Developer Challenge - GDG Belgaum
Google Cloud Developer Challenge - GDG Belgaum
 
How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...
 

Más de Simon Willison

Building Things Fast - and getting approval
Building Things Fast - and getting approvalBuilding Things Fast - and getting approval
Building Things Fast - and getting approval
Simon Willison
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 

Más de Simon Willison (20)

How Lanyrd does Geo
How Lanyrd does GeoHow Lanyrd does Geo
How Lanyrd does Geo
 
Cheap tricks for startups
Cheap tricks for startupsCheap tricks for startups
Cheap tricks for startups
 
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
 
Building Lanyrd
Building LanyrdBuilding Lanyrd
Building Lanyrd
 
How we bootstrapped Lanyrd using Twitter's social graph
How we bootstrapped Lanyrd using Twitter's social graphHow we bootstrapped Lanyrd using Twitter's social graph
How we bootstrapped Lanyrd using Twitter's social graph
 
Web Services for Fun and Profit
Web Services for Fun and ProfitWeb Services for Fun and Profit
Web Services for Fun and Profit
 
Tricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationTricks & challenges developing a large Django application
Tricks & challenges developing a large Django application
 
Advanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
Advanced Aspects of the Django Ecosystem: Haystack, Celery & FabricAdvanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
Advanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
 
How Lanyrd uses Twitter
How Lanyrd uses TwitterHow Lanyrd uses Twitter
How Lanyrd uses Twitter
 
ScaleFail
ScaleFailScaleFail
ScaleFail
 
Building Things Fast - and getting approval
Building Things Fast - and getting approvalBuilding Things Fast - and getting approval
Building Things Fast - and getting approval
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The Libraries
 
Building crowdsourcing applications
Building crowdsourcing applicationsBuilding crowdsourcing applications
Building crowdsourcing applications
 
Evented I/O based web servers, explained using bunnies
Evented I/O based web servers, explained using bunniesEvented I/O based web servers, explained using bunnies
Evented I/O based web servers, explained using bunnies
 
Cowboy development with Django
Cowboy development with DjangoCowboy development with Django
Cowboy development with Django
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with Django
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Class-based views with Django
Class-based views with DjangoClass-based views with Django
Class-based views with Django
 
Web App Security Horror Stories
Web App Security Horror StoriesWeb App Security Horror Stories
Web App Security Horror Stories
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror Stories
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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...
 

I've (probably) been using Google App Engine for a week longer than you have

  • 1. I’ve (probably) been using Google App Engine for a week longer than you have Simon Willison - http://simonwillison.net/ BarCamp London 4 31st May 2008
  • 2. Except you have to re-write your whole application If you totally rethink the way you use a database
  • 3. What it can do • Serve static files • Serve dynamic requests • Store data • Call web services (sort of) • Authenticate against Google’s user database • Send e-mail, process images, use memcache
  • 4. The dev environment is really, really nice • Download the (open source) SDK • a full simulation of the App Engine environment • dev_appserver.py myapp for a local webserver • appcfg.py update myapp to deploy to the cloud
  • 5. Options • You have to use Python • You can choose how you use it: • CGI-style scripts • WSGI applications • Google’s webapp framework • Django (0.96 provided, or install your own)
  • 6. Hello World # helloworld.py print quot;Content-Type: text/htmlquot; print print quot;Hello, world!quot; # app.yaml application: simonwillison-helloworld version: 1 runtime: python api_version: 1 handlers: - url: /.* script: helloworld.py
  • 7. With webapp and WSGI import wsgiref.handlers from google.appengine.ext import webapp class MainPage(webapp.RequestHandler):   def get(self):     self.response.headers['Content-Type'] = 'text/html'     self.response.out.write('Hello, webapp World!') def main():   application = webapp.WSGIApplication( [('/', MainPage)], debug=True)   wsgiref.handlers.CGIHandler().run(application) if __name__ == quot;__main__quot;:   main()
  • 8. With Django from django.conf.urls.defaults import * from django.http import HttpResponse def hello(request): return HttpResponse(quot;Hello, World!quot;) urlpatterns = patterns('', ('^$', hello), ) (And django_dispatch.py for boilerplate)
  • 9. Don't use CGI: it requires reloading for every hit • Why use Django over webapp? • Django has easy cookies and custom 500 errors • Django is less verbose • Django middleware is really handy • You can use other WSGI frameworks if you like
  • 10. Static files # in app.yaml handlers: - url: /css static_dir: css - url: /img static_dir: img - url: /favicon.ico static_files: img/favicon.ico upload: img/favicon.ico mime_type: image/x-icon
  • 12. “Bigtable is a distributed storage system for managing structured data that is designed to scale to a very large size: petabytes of data across thousands of commodity servers. Many projects at Google store data in Bigtable, including web indexing, Google Earth, and Google Finance.”
  • 13. The App Engine datastore • Apparently based on BigTable • Absolutely not a relational database • No joins (they do have “reference fields”) • No aggregate queries - not even count()! • Hierarchy affects sharding and transactions • All queries must run against an existing index
  • 14. Models and entities • Data is stored as entities • Entities have properties - key/value pairs • An entity has a unique key • Entities live in a hierarchy, and siblings exist in the same entity group - these are actually really important for transactions and performance • A model is kind of like a class; it lets you define a type of entity
  • 15. AppEngine Models from google.appengine.ext import db class Account(db.Model): slug = db.StringProperty(required=True) owner = db.UserProperty() onlyme = db.BooleanProperty() referrers = db.StringListProperty() (There is a ReferenceProperty, but I haven’t used it yet)
  • 16. Inserting data account = Account( key_name = slug, slug = slug, referrers = ['...', '...'], onlyme = False, owner = users.get_current_user() ) db.put(account) # Or account.put() Browser.get_or_insert(key_name, parent = account, slug = browser_slug )
  • 17. Running queries Browser.all().ancestor(account) Account.gql(quot;WHERE slug = :1quot;, slug)) Story.all().filter( 'title =', 'Foo' ).order('-date')
  • 18. BUT... • All queries must run against an existing index • Filtering or sorting on a property requires that the property exists • Inequality filters are allowed on one property only • Properties in inequality filters must be sorted before other sort orders • ... and various other rules • Thankfully the dev server creates most indexes for you automatically based on usage
  • 19. How indexes are used 1. The datastore identifies the index that corresponds with the query’s kind, filter properties, filter operators, and sort orders. 2. The datastore starts scanning the index at the first entity that meets all of the filter conditions using the query’s filter values. 3. The datastore continues to scan the index, returning each entity, until it finds the next entity that does not meet the filter conditions, or until it reaches the end of the index.
  • 20. Further limitations • If you create a new index and push it live, you have to wait for it to rebuilt • This can take hours, and apparently can go wrong • You can’t safely grab more than about 500 records at once - App Engine times out • You can’t delete in bulk
  • 21. Other random notes • You have to use the URL Fetch API to do HTTP requests (e.g. for web services) - and it times out agressively at about 5 seconds • The Google accounts Users API is ridiculously easy to use, but... • no permanent unique identifier; if the user changes their e-mail address you’re screwed • The new image and memcache APIs are neat
  • 22. Final thoughts • It’s really nice not to have to worry about hosting • But... the lack of aggregate queries and ad-hoc queries really hurts • Perfect for small projects you don’t want to worry about and big things which you’re sure will have to scale • Pricing is comparable to S3 - i.e. stupidly cheap
  • 23. Pricing • $0.10 - $0.12 per CPU core-hour • $0.15 - $0.18 per GB-month of storage • $0.11 - $0.13 per GB outgoing bandwidth • $0.09 - $0.11 per GB incoming bandwidth