“太多争论”在dataStore中创建新实体时 [英] "Too much contention" when creating new entity in dataStore

查看:157
本文介绍了“太多争论”在dataStore中创建新实体时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上,我的GAE应用程序生成了几个错误日志:对这些数据存储实体的争用太多了,请再试一次。#p#分页标题#e#在我看来,只有当多个请求尝试修改同一实体同一实体组中的实体时,才会发生此类错误。

当我得到这个错误时,我的代码插入了新的实体。我很困惑。这是否意味着我们可以创建新实体的速度有限制?



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

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

#调用顺序
stats = ExternalAPIStats(userid = current_uid,api =eapi:hr:get_by_id,start_at = start_at,end_at = end_at)
stats.put()#**太多争用**发生在这里

这对我来说很神秘。我想知道如何处理这个问题。请让我知道是否有任何建议。



干杯!

解决方案

没有看到如何调用(你显示调用代码,但它多久被称为,通过循环或许多页面同时调用相同的时间),但我相信这个问题更好地解释here 。特别是


如果以高速率创建新实体并且像时间戳那样单调增加索引属性,您也会看到此问题,因为这些属性是Bigtable中索引表中行的关键。


以'start_at'为罪魁祸首。本文章更详细地解释。

可能(尽管未经测试)尝试分批进行投注。你在'start_at'字段上运行查询吗?如果不删除它的索引,也将解决问题。



投资者是如何调用的(即我在上面提到的循环,多个页面调用)?因此,缩小问题可能会更容易。


dear all

This morning my GAE application generated several error log: "too much contention on these datastore entities. please try again.". In my mind, this type of error only happens when multiple requests try modify the same entity or entities in the same entity group.

When I got this error, my code is inserting new entities. I'm confused. Does this mean there is a limitation of how fast we can create new entity?

My code of model definition and calling sequence is show below:

# 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

That's pretty mysterious to me. I was wondering how I shall deal with this problem. Please let me know if any suggestion.

Cheers!

解决方案

Without seeing how the calls are made(you show the calling code but how often is it called, via loop or many pages calling the same put at the same time) but I believe the issue is better explained here. In particular

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.

with the 'start_at' being the culprit. This article explains in more detail.

Possibly (though untested) try doing your puts in batches. Do you run queries on the 'start_at' field? If not removing its indexes will also fix the issue.

How is the puts called (ie what I was asking above in a loop, multiple pages calling)? With that it might be easier to narrow down the issue.

这篇关于“太多争论”在dataStore中创建新实体时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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