The Wayback Machine - https://web.archive.org/web/20100220195348/http://web2py.com:80/book/default/section/11/13

11.13. Google App Engine

It is possible to run web2py code on Google App Engine (GAE) (link), including DAL code, with some limitations. The GAE platform provides several advantages over normal hosting solutions:

  • Ease of deployment. Google completely abstracts the underlying architecture.
  • Scalability. Google will replicate your app as many times as it takes to serve all concurrent requests
  • BigTable. On GAE, instead of a normal relational database, you store persistent information in BigTable, the datastore Google is famous for.

The limitations are:

  • You have no read or write access to the file system.
  • No transactions
  • You cannot perform complex queries on the datastore, in particular there are no JOIN, OR, LIKE, IN, and DATE/DATETIME operators.

This means that web2py cannot stores sessions, error tickets, cache files and uploaded files on disk; they must be stored somewhere else. Therefore, on GAE, web2py automatically stores all uploaded files in the datastore, whether or not "upload" Field(s) have a uploadfield attribute. You have to be explicit about where to store sessions and tickets:

You can store them in the datastore too:

1.
2.
db = DAL('gae')
session.connect(request,response,db)

Or, you can store them in memcache:

1.
2.
3.
4.
5.
6.
7.
from gluon.contrib.gae_memcache import MemcacheClient
from gluon.contrib.memdb import MEMDB
cache.memcache = MemcacheClient(request)
cache.ram = cache.disk = cache.memcache

db = DAL('gae')
session.connect(request,response,MEMDB(cache.memcache))

The absence of transactions and typical functionalities of relational databases are what sets GAE apart from other hosting environment. This is the price to pay for high scalability. If you can leave with these limitations, then GAE is an excellent platform. If you cannot, then you should consider a regular hosting platform with a relational database.

If a web2py application does not run on GAE, it is because of one of the limitations discussed above. Most issues can be resolved by removing JOINs from web2py queries and denormalizing the database.

To upload your app in GA,E we recommend using the Google App Engine Launcher. You can download the software from ref. (link).

Choose [File][Add Existing Application], set the path to the path of the top-level web2py folder, and press the [Run] button in the toolbar. After you have tested that it works locally, you can deploy it on GAE by simply clicking on the [Deploy] button on the toolbar (assuming you have an account).

image

On Windows and Linux systems, you can also deploy using the shell:

1.
2.
cd ..
/
usr/local/bin/dev_appserver.py web2py

When deploying, web2py ignores the admin, examples, and welcome applications since they are not needed. You may want to edit the app.yaml file and ignore other applications as well.

On GAE, the web2py tickets/errors are also logged into the GAE administration console where logs can be accessed and searched online.

image

You can detect whether web2py is running on GAE using the variable

1.
request.env.web2py_runtime_gae
Previous / Next


Related Wiki Pages



User Comments



login to post
    © 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
    The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.