通过减少实体大小来提高App Engine的性能 [英] Improve App Engine performance by reducing entity size

查看:92
本文介绍了通过减少实体大小来提高App Engine的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标是减少运行频率很高的代码的CPU成本和响应时间,并且每次都必须使用db.get()数百个键。

这是否甚至可以工作?

我可以期望db.get()的几百个键
的API时间大致线性减少,因为我减少了实体的大小?
当前实体附有以下数据:9字符串,9
布尔值,8整数,1 GeoPt,2日期时间,1文本(平均大小〜100字节
FWIW),1参考, 1 StringList(平均大小500字节)。目标是
将这些数据的绝大部分转移到相关的类中,这样主模型的
内核获取就会很快。

如果确实有效,它是如何实现的?



重构之后,我仍然会产生相同的结果
高成本提取现有实体?该文档说,模型的所有
属性都是同时获取的。旧的
不需要的属性是否仍然通过我的硬币上的RPC传输,而用户
是否等待?换句话说:如果我想减少我的实体的加载时间,那么
是否需要将旧实体迁移到具有新
定义的实体? 如果是这样,是它足以重新放置()该实体,或者必须在全新的密钥下保存
吗?



示例



考虑:

  class Thing(db.Model):
text = db.TextProperty()
strings = db.StringListProperty()
num = db.IntegerProperty()

thing = Thing(key_name ='thing1',text ='x'* 10240,
strings = ['y'* 500 for i in range(10)],num = 23)
thing.put()

假设我重新定义Thing以简化流程并提升新版本:

  class Thing(db.Model):
num = db.IntegerProperty()

然后我再次获取它:

  thing_again = Thing.get_by_key_name('thing1')

时间为这个实体?

解决方案

按照顺序回答您的问题:


  • 是的,拆分模型会减少获取时间,但可能不是线性的。对于像你这样的相对较小的模型,差异可能并不大。大列表属性是导致提取时间增加的主要原因。

  • 因为数据存储区不知道模型,所以在您更改模型后获取实体时,旧属性仍将被传输。然而,即使您调用.put(),删除的属性仍将被存储。目前,有两种消除旧属性的方法:将所有现有实体替换为新的实体,或者使用较低级别的api.datastore接口,该接口类似于字典,便于删除键。


The objective is to reduce the CPU cost and response time for a piece of code that runs very often and must db.get() several hundred keys each time.

Does this even work?

Can I expect the API time of a db.get() with several hundred keys to reduce roughly linearly as I reduce the size of the entity? Currently the entity has the following data attached: 9 String, 9 Boolean, 8 Integer, 1 GeoPt, 2 DateTime, 1 Text (avg size ~100 bytes FWIW), 1 Reference, 1 StringList (avg size 500 bytes). The goal is to move the vast majority of this data to related classes so that the core fetch of the main model will be quick.

If it does work, how is it implemented?

After a refactor, will I still incur the same high cost fetching existing entities? The documentation says that all properties of a model are fetched simultaneously. Will the old unneeded properties still transfer over RPC on my dime and while users wait? In other words: if I want to reduce the load time of my entities, is it necessary to migrate the old entities to ones with the new definition? If so, is it sufficient to re-put() the entity, or must I save under a wholly new key?

Example

Consider:

class Thing(db.Model):
    text    = db.TextProperty()
    strings = db.StringListProperty()
    num     = db.IntegerProperty()

thing = Thing(key_name='thing1', text='x' * 10240,
      strings = ['y'*500 for i in range(10)], num=23)
thing.put()

Let's say I re-define Thing to be streamlined and push up a new version:

class Thing(db.Model):
    num = db.IntegerProperty()

And I fetch it again:

thing_again = Thing.get_by_key_name('thing1')

Have I reduced the fetch time for this entity?

解决方案

To answer your questions in order:

  • Yes, splitting up your model will reduce the fetch time, though probably not linearly. For a relatively small model like yours, the differences may not be huge. Large list properties are the leading cause of increased fetch time.
  • Old properties will still be transferred when you fetch an entity after the change to the model, because the datastore has no knowledge of models.
  • Also, however, deleted properties will still be stored even once you call .put(). Currently, there's two ways to eliminate the old properties: Replace all the existing entities with new ones, or use the lower-level api.datastore interface, which is dict-like and makes it easy to delete keys.

这篇关于通过减少实体大小来提高App Engine的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆