【发布时间】:2013-02-02 19:59:24
【问题描述】:
使用 Google App Engine,我很好奇是否有人可以阐明使用 ComputedProperty 与按需计算相关模型的计数的性能特征(读取和写入)。
ComputedProperty 具有允许对属性进行索引的明显优势,但我只是好奇读取和写入的速度相比有多快。
例如,给定两个模型:
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)
这个问题实际上分解成如下内容:
- 写
Owner有多慢,因为它有cars_count_prop? - 阅读
cars_count_prop比阅读cars_count快多少?
或者,换句话说:
- 读写各自的渐近计算复杂度 (big-O) 是多少?
- 平均案例计算复杂度是多少 - 对于Jay Leno 以外的人(即每个
Owner的少量Car实例)? - 读取和写入的等待有多少是计算复杂度,有多少是数据库/memcache 查找?
【问题讨论】:
标签: google-app-engine google-cloud-datastore app-engine-ndb