简体   繁体   English

优化appengine实体密钥用法

[英]Optimizing appengine entity key usage

Should I care about locality of entities on the Google App Engine datastore? 我应该关心Google App Engine数据存储区中实体的位置吗? Should I use custom entity key names for that? 我应该使用自定义实体密钥名称吗?

For example, I could use "$article_uuid,$comment_id" as the key name of a Comment entity. 例如,我可以使用“$ article_uuid,$ comment_id”作为Comment实体的键名。 Will it improve the speed of fetching all comments for an article? 它会提高获取文章所有评论的速度吗? Or is it better to use shorter keys? 或者使用较短的键更好?

Is it a good practice to use the key in this way? 以这种方式使用密钥是一种好习惯吗? I could use the "$article_uuid,$comment_id" key name also instead of an index: 我也可以使用“$ article_uuid,$ comment_id”键名而不是索引:

def get_comments(article_uuid, limit=1000):
    key_prefix=db.Key.from_path('Comment', article_uuid)
    q = Comment.gql("where __key__ > :key_prefix and __key__ < :range_end",
        key_prefix=key_prefix, range_end=key_prefix+chr(ord(',')+1))
    return q.fetch(limit)

The locality of your data will be improved with your key_name scheme ( ref, see slide 40 ) - since your key_name is prefixed with the corresponding article's ID, comments for a given article should be stored near each other. 使用您的key_name方案( 参见幻灯片40 )可以改善数据的位置 - 由于您的key_name以相应文章的ID为前缀,因此给定文章的注释应该彼此靠近存储。

The key_name you proposed doesn't seem like it would be too long. 您提出的key_name似乎不会太长。 I don't think you'll see too much difference between that and shorter keys in terms of storage space or serialization/deserialization time. 我认为在存储空间或序列化/反序列化时间方面,你会发现它与短键之间存在太大差异。 I expect that the size of the Comment entity will be dominated by the rest of the entity. 我希望Comment实体的大小将由实体的其余部分支配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM