turtletramp's blog

Tips & Tricks - Google App Engine
  1. coding related
  2. Howto lower costs
    1. robots.txt
    2. ways to lower the CPU usage time / instance hours
      1. cache-control headers
      2. other options
  3. Datastore
    1. String properties
    2. asynchronism of writes and immediate queries

I stumbled over an issue where I could not enter enough data into a form text area. The reason was that I used the form method GET. And it seems that Google appengine has a restriction on the length of the URL of a GET request. I then change do method POST and everything works find :)

Howto lower costs

details see here


Some of your traffic / load may be generated by robots / web spiders (I will only refer to these by the term robot) gaining information about your site. There are good and bad robots. You can not do a lot about bad robots. But most of the time you will want the good robots like the biggest ones like the one from Google search engine. So it's a good idea to use a well defined robots.txt to inform the robot which sites makes sense to be indexed and which are not. Things that you may not want to be indexed:

  • scripts
  • images
  • REST APIs that may create heavy READ load on your Datastore and others.

See also Googles info

ways to lower the CPU usage time / instance hours

cache-control headers

If your site does not change often use cache-control headers to allow servers to cache content for you and do not always request it from the main server where the App engine would count instance hours

A good overview can be found here.

other options

use static files these do not cost instance hours


String properties

Good: They can be easily used and can be included in indexes
Bad: They can only store up to 500 characters

Use the .datastore.Text object to store more characters inside a datastore property.

When I first wrote the source code for this blog I did not read the documentation carefully enough so I have provided a normal String object holding the main article text body to the datastore setProperty method. By doing this a String property was created and so I was limited to 500 characters; which I noticed when trying to write my first real article.
To solve this I then changed to use a .datastore.Text object to store my article texts. But from now on I could not use the datastore engine to run an indexed search on my article texts.

asynchronism of writes and immediate queries

I am still beginner with using the GAE datastore. But here are some thoughts that may help you in the special situation that you cannot figure out why data that you just before wrote to the datastore is not part of a following query when you execute the query very early after the write / put.

I needed a simple web form in a web site backend where a user enters data for a new event to be shown on the website. And after a new event entry is .put to the datastore the list of available events should be shown to the user. But while this was very fast implemented I recogniced that my newly put entity (= a data object written to the datastore) needs some seconds until a query executed on the same kind of entities would also include the last created one. I googled a lot. So far I do not have a 100% answer as I am still lacking some tests but...

It turns out that the main issue of having consistent data is to take care about this. To get strong consitency a query needs to define an acestor. So it's a good idea to group strongly related entities together with one ancestore to achieve strong cosistency. (ATTENTION: This creates slow write performance! So you need to take care if the write performance is good enough or if you simply take care by yourself to have your results consistent)