GAE NDB ComputedProperty performance versus query-by-query for number of related models

Using Google App Engine I am just curious if anyone can highlight the performance characteristics (read and write) when used ComputedProperty

versus compute on demand of the number of the linked model.

ComputedProperty has the distinct advantage of allowing the property to be indexed, but I'm just wondering how fast the comparison is read and written.

For example, for two models:

class Car(ndb.Model):
  owner_key = ndb.KeyProperty(kind='Owner', indexed=True)

class Owner(ndb.Model)
   def cars_count(self):
       ndb.query(Car.owner_key == self.key).count()

   cars_count_prop = ndb.ComputedProperty(cars_count)

      

The question really breaks down into something like the following:

  • how much slower Owner

    does it record because it has cars_count_prop

    ?
  • how much faster is cars_count_prop

    it readable than cars_count

    ?

Or, in other words:

  • What is the asymptotic computational complexity (big-O) of reading and writing?
  • what is the average computational complexity of the case - for people other than Jay Leno (i.e. small number of instances Car

    per Owner

    )?
  • How much is computational complexity to read and write, and how many database / memcache lookups?
+3


source to share


1 answer


The time when you update the owner object, the request will be recalculated. This may not be good. The complexity of the request is not an issue. But if you really want to know, you need to compare it.



+6


source







All Articles