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 hascars_count_prop
? - how much faster is
cars_count_prop
it readable thancars_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
perOwner
)? - How much is computational complexity to read and write, and how many database / memcache lookups?
+3
source to share