【问题标题】:Appengine NDB: Putting 880 rows, exceeding datastore write ops quota. Why?Appengine NDB:放置 880 行,超过数据存储写入操作配额。为什么?
【发布时间】:2013-06-09 08:16:28
【问题描述】:

我有一个使用 put_async() 将 880 行导入 NDB 数据存储的应用程序。每当我运行此导入时,它都会超过 50,000 次数据存储的每日写入操作配额。

我试图了解为什么这项操作如此昂贵,以及如何才能保持在配额之下。

有 13 列,如下所示:

stringbool = ['true', 'false']
class BeerMenu(ndb.Model):
  name = ndb.StringProperty()
  brewery = ndb.StringProperty()
  origin = ndb.StringProperty()
  abv = ndb.FloatProperty()
  size = ndb.FloatProperty()
  meas = ndb.StringProperty()
  price = ndb.FloatProperty()
  active = ndb.StringProperty(default="false", choices=stringbool)
  url = ndb.StringProperty()
  bartender = ndb.StringProperty()
  lineno = ndb.IntegerProperty()
  purdate = ndb.DateProperty()
  costper = ndb.FloatProperty()

我已将索引缩减为一个:

- kind: BeerMenu
  properties:
    - name: brewery
    - name: name

根据 SDK 数据存储查看器,每行是 29 次写入操作,因此将生成 25520 次写入!我假设索引消耗了其余的写入操作,但我不知道具体有多少,因为 AppEngine 只是说我已经超出了配额。

减少写入操作次数的最佳策略是什么?

【问题讨论】:

  • 更新:我意识到 ndb.StringProperty() 默认是索引的。通过在其中许多项目上设置 indexed=False,我可以将写入操作减少到 18。我仍然不了解与 index.yaml 的关系。

标签: google-app-engine python-2.7 google-cloud-datastore app-engine-ndb


【解决方案1】:

默认情况下,除 text 和 blob 属性外的所有属性都已编入索引。因此,如果您取消对字符串属性的索引,所有浮点、整数和日期属性仍会被索引。您应该将indexed=False 添加到其他属性以减少写入。

index.yaml 中列出的索引是属性索引的附加索引。 index.yaml 索引用于有序查询和关系查询(即,日期 > date_property 的查询将在 index.yaml 中生成条目)。

【讨论】:

  • 所以有索引再有索引!谢谢你的解释。
  • 哇哦!由于我已将所有我不查询的浮点、整数和日期属性设置为 indexed=False,因此每行写入操作已降至 4 个。
  • @Irving 我会说喜欢。有索引,甚至在那之前就有索引......
【解决方案2】:

在这里,查看数据存储调用的成本部分,让您了解更多:

Paid Apps: Budgeting, Billing, and Buying Resources

希望这也有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多