We will build a python app with App Engine Memcache to store entries ephemerally.
Memcache is not persistent storage - it is cached storage useful for speeding up requests, and also reduces infrastructure costs on App Engine.
We will:
- we will clone the app using an existing compute instance
- deploy our app via the instance
- view the cached data
Start the compute instance created in #9:
-
visit Compute Engine
-
start the instance
-
open Cloud Shell (SDK is always the latest, as opposed to when SDK is run locally)
-
ssh onto our instance
$ glcoud compute ssh <instance-name>
-
clone the app
$ git clone https://github.com/GoogleCloudPlatformTraining/cp100-appengine-memcache-python.git $ cd cp100-appengine-memcache-python
The app is comprised of 3 main files:
- guestbook.py
- the backend of the application
- index.html
- data passed to index.html via the
jinja
templating engine imported in our application
- data passed to index.html via the
- app.yaml
- configuration file that
gcloud app deploy
uses to deploy our application to App Engine
- configuration file that
Our app.yaml
looks like this:
# application is the project id in GAE
# this will be removed and a project id specified when running the deploy command
application: your-app-id
# the version of your app
# this is automatically generated, or specified via the deploy command, and so
# will also be removed
version: 1
runtime: python27
api_version: 1
threadsafe: true
version: latest
# routing rules
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: guestbook.application
libraries:
# webapp2 handles requests to the application
- name: webapp2
version: latest
# jinja2 is responsible for templating
- name: jinja2
version: latest
To deploy the app:
-
remove
application
andversion
fromapp.yaml
-
run the deploy command
# deploy our app $ gcloud app deploy app.yaml --project <project-id>
-
when the command succeeds we can get the URL to view our app using
gcloud
:$ gcloud app browse --project=<project-id> <project-id>.appspot.com
-
at App Engine we can see that we have an app running, and can access it via the URL in the to-right of the logging area
-
at GAE Versions we can see current version running, and also access the app from its line item
-
We can add cached data to the app, and see the requests logged on our app dashboard
-
At GAE Memcache we can see how many times there has been a cache hit. Refreshing the app will increment the hits count on this page.
-
At GAE Instances we can see the total number of requests on our application
-
Under Logging, once selecting 'GAE Application' from the dropdown, we can see details of all requests
-
We can view the cached data in Memcache:
- click 'Find a key'
- select 'Python string' from 'Key type'
- use 'entries' in 'key'
- click 'Find'
- click 'entries' in the table that comes back with the response
- look at the fine entries stored in Memcache
-
change the HTML file so that the difference can be seen
-
deploy the app with a new version
$ gcloud app deploy app.yaml --project <project-id> --version 2
-
under GAE Versions we can see our new version. The previous version now has a different URL, with the latest version having the original URL
-
we can set traffic splitting to split traffic between multiple versions here, too
-
on the dashboard we can see metrics for specific version using the 'version' select menu
- GAE instance doesn't need to be stopped, as usage limits are generous
- Make sure to stop the compute instance used to deploy the app