[英]What's faster and less expensive in terms of datastore writes? Storing data in ndb.StructuredProperty or storing separately as child entities
I am currently storing data in my appengine ndb datastore using this model 我目前正在使用此模型将数据存储在我的appengine ndb数据存储区中
class BundleModel (ndb.Model):
product_vals=ndb.StructuredProperty(ProductModel,repeated=True)
ProductModel is as follows: ProductModel如下:
class ProductModel(ndb.Model):
p_created=ndb.DateTimeProperty(auto_now_add=True)
p_updated=ndb.DateTimeProperty(auto_now=True)
p_title=ndb.StringProperty()
p_link=ndb.StringProperty()
p_categ=ndb.StringProperty()
p_categ_alt=ndb.StringProperty()
p_value=ndb.FloatProperty()
p_location=ndb.StringProperty()
p_avail=ndb.BooleanProperty(default=True)
p_mod=ndb.BooleanProperty(default=False)
I only put BundleModel in the datastore and the ProductModel entities are embedded in each entity as a list. 我只将BundleModel放在数据存储区中,并且ProductModel实体作为列表嵌入在每个实体中。
I am wondering if this is an expensive and slow method to store the data. 我想知道这是否是一种昂贵且缓慢的数据存储方法。 Would it be better to store each ProductModel as a child entity, with a BundleModel as the parent? 将每个ProductModel存储为一个子实体,以BundleModel作为父实体,会更好吗?
In this case, each request for BundleModel would translate into multiple requests for ProductModels. 在这种情况下,对BundleModel的每个请求都将转换为对ProductModels的多个请求。 So is the trade-off, one request for a large chunk of data versus multiple requests (about ten or so) for small chunks of data? 那么,要权衡一下,一个请求大数据块而不是多个请求(大约十个左右)吗? In terms of writing data, I would then write small chunks separately instead of modifying one big chunk. 在写数据方面,我将分别写小块,而不是修改一个大块。
What are the ramifications of such a change in terms of cost, speed, and any other parameters? 这种变化在成本,速度和任何其他参数方面的后果是什么?
Thanks! 谢谢!
No, using structured property will be faster and cheaper then using a separate child entities. 不,与使用单独的子实体相比,使用结构化属性会更快,更便宜。
The way structured property works is by flattening the structure and automagically creating new properties in the entity for each property in the structure. 结构化属性的工作方式是通过展平结构并为该结构中的每个属性自动在实体中创建新属性。 In your case your BundleModel
entity would get autogenerated properties: product_vals.p_created
, product_vals.p_updated
, etc.. 在您的情况下,您的BundleModel
实体将获得自动生成的属性: product_vals.p_created
, product_vals.p_updated
等。
Structured property is better as it only stores one entity, instead of two or more (parent+child). 结构化属性更好,因为它仅存储一个实体,而不是两个或多个(父代+子代)。 This makes it faster and cheaper. 这使得它更快,更便宜。 Note that there is no cost per entity size when accessing it. 请注意,访问实体时,每个实体大小都没有成本。
Note on limitations: 限制说明:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.