python - 在 dataStore 中创建新实体时为 "Too much contention"

标签 python google-app-engine google-cloud-datastore

今天早上我的 GAE 应用程序生成了几个错误日志:“这些数据存储实体上的争用太多。请重试。”。在我看来,这种类型的错误只会在多个请求尝试修改同一实体同一实体组 中的实体时发生。

当我收到此错误时,我的代码正在插入新实体。我很困惑。这是否意味着我们创建新实体的速度存在限制?

我的模型定义和调用顺序代码如下:

# model defnition
class ExternalAPIStats(ndb.Model):
    uid = ndb.StringProperty()
    api = ndb.StringProperty()
    start_at = ndb.DateTimeProperty(auto_now_add=True)
    end_at = ndb.DateTimeProperty()

# calling sequence
stats = ExternalAPIStats(userid=current_uid, api="eapi:hr:get_by_id", start_at=start_at, end_at=end_at)
stats.put()  # **too much contention** happen here

这对我来说很神秘。我想知道我将如何处理这个问题。如果有任何建议,请告诉我。

最佳答案

没有看到调用是如何进行的(你显示了调用代码,但它被调用的频率是多少,通过循环或许多页面同时调用同一个 put)但我相信这个问题得到了更好的解释 here .特别是

You will also see this problem if you create new entities at a high rate with a monotonically increasing indexed property like a timestamp, because these properties are the keys for rows in the index tables in Bigtable.

“start_at”是罪魁祸首。这article解释得更详细。

可能(尽管未经测试)尝试分批进行放置。您是否在“start_at”字段上运行查询?如果不删除其索引也将解决此问题。

puts 是如何调用的(即我在上面循环中询问的内容,多个页面调用)?这样可能更容易缩小问题的范围。

关于python - 在 dataStore 中创建新实体时为 "Too much contention",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17308179/

相关文章:

python - 将类似系列的数据文件导入 pandas

python - 有没有一种方法可以对计算 Spearman 相关性及其 p 值的嵌套循环进行矢量化?

eclipse - 无法完成安装 Google Plugin for eclipse

python - 使用 paypal 沙箱 API 时出错

go - 使用 golang/protobuf 时在数据存储中构建错误

android - 在 android 中的 Google AppEngine 上插入同一表后更新数据库时出现 503 错误

python - 如何从字典中构建比蛮力更好的 Plinko 单词板?

python - 如何调用类中包含的异步函数?

java - 某些 Google App Engine 实例中的负载而其他实例中的负载非常小。为什么?

google-app-engine - 将十六进制值存储为字节导致丢失