Google Datastore – 没有看到每个实体组每秒1次写入的限制

huangapple go评论88阅读模式
英文:

Google Datastore - Not Seeing 1 Write per Second per Entity Group Limitation

问题

我已经阅读了很多关于强一致性与最终一致性的文章,以及使用祖先/实体组和Google Datastore每个实体组每秒一次写入限制的内容。

然而,在我的测试中,我从未遇到过异常Too much contention on these datastore entities. please try again. 我正在努力理解是否我对这些概念有误解或者是否缺少了某个重要的部分。

我创建实体的方式如下:

func usersKey(c appengine.Context) *datastore.Key {
	return datastore.NewKey(c, "User", "default_users", 0, nil)
}

func (a *UserDS) UserCreateOrUpdate(c appengine.Context, user models.User) error {

	key := datastore.NewKey(c, "User", user.UserId, 0, usersKey(c))
	_, err := datastore.Put(c, key, &user)

	return err
}

然后使用datastore.Get来读取它们。我知道读取不会有问题,因为我是通过键进行查找的,但是如果有大量的用户创建和更新他们的信息,理论上我会不断达到每秒一次写入的最大限制。

为了测试这一点,我尝试一次创建25个用户(使用上述方法,没有批处理),然而我没有记录到任何异常,这篇帖子暗示我应该会遇到异常:https://stackoverflow.com/questions/10454467/google-app-engine-hrd-what-if-i-exceed-the-1-write-per-second-limit-for-writin

我漏掉了什么?是不是只有查询才会有争用问题,25个用户不足够多,还是我完全忽略了其他什么?

英文:

I've read a lot about strong vs eventual consistency, using ancestor / entity groups, and the 1 write per second per entity group limitation of Google Datastore.

However, in my testing I have never hit the exception Too much contention on these datastore entities. please try again. and am trying to understand whether I'm misunderstanding these concepts or missing a piece of the puzzle.

I'm creating entities like so:

func usersKey(c appengine.Context) *datastore.Key {
	return datastore.NewKey(c, "User", "default_users", 0, nil)
}

func (a *UserDS) UserCreateOrUpdate(c appengine.Context, user models.User) error {

	key := datastore.NewKey(c, "User", user.UserId, 0, usersKey(c))
	_, err := datastore.Put(c, key, &user)

	return err
}

And then reading them with datastore.Get. I know I won't have issues reading since I'm doing a lookup by key, but if I have a high volume of users creating and updating their information, I would theoretically hit the max of 1 write per second constantly.

To test this, I attempted to create 25 users at once (using the above methods, no batching), yet I don't log any exceptions, which this post implies I should: https://stackoverflow.com/questions/10454467/google-app-engine-hrd-what-if-i-exceed-the-1-write-per-second-limit-for-writin

What am I missing? Does the contention only apply to querying, is 25 not a high enough volume, or am I missing something else entirely?

答案1

得分: 4

根据文档:

对单个实体组的写操作在App Engine数据存储中是串行的,因此对于更新一个实体组的速度有一定的限制。一般来说,这个限制在每秒1到5次更新之间;一个好的指导原则是,如果你预计一个实体组需要在一个较长的时间内每秒承受超过一次更新,那么你应该考虑重新设计架构。

请注意“较长的时间”这个词。每秒1次更新基本上是最低的保证吞吐量。在任何给定的时刻,你可能能够实现更高的水平,但Google警告你不要为这些水平始终可用而进行架构设计。

英文:

From the documentation:

> Writes to a single entity group are serialized by the App Engine
> datastore, and thus there's a limit on how quickly you can update one
> entity group. In general, this works out to somewhere between 1 and 5
> updates per second; a good guideline is that you should consider
> rearchitecting if you expect an entity group to have to sustain more
> than one update per second for an extended period.

Note the words "extended period". 1 update per second is basically a minimum guaranteed throughput. At any given moment you may be able to achieve a significantly higher levels, but Google is warning you not to architect for those levels to be always available.

答案2

得分: 3

限制是针对实体组的,这意味着你可以创建任意数量的用户而没有限制(这就是扩展的优势),只要它们不共享相同的祖先。

一旦你开始使用用户键作为其他实体的祖先,使它们成为同一组的一部分,那么对它进行的更改就会有限制,每秒只能进行多少次更改。

顺便说一下,这是一个概括,很可能你每秒只能进行大约5次更改,这个限制是由于实体组的事务属性,所以有一种包含必须按顺序执行的更改的表,因此你必须进行锁定,从而有了有限的吞吐量。

尽管如此,经验法则是认为你每秒只能进行1次更改,以迫使自己考虑如何在这些条件下工作。

还有,正如前面提到的,这只与更新数据库有关,获取和查询应根据需要进行扩展。

英文:

The limitation is per entity group, that means you could create as many users as you need without limitation (that's where scaling shines), as long as they don't share the same ancestor.

Things change once you start using the user key as the ancestor of other entities, making them part of the same group and thus having a limit on how many changes you can make to it per second.

Btw this is a generalization, most likely you will be able to make ~5 changes per second, this limitation exist because of the transactional properties of an entity group, so there's some kind of table with changes that must be executed sequentially, so you have to lock, and thus there's limited throughput.

Still, rule of thumb is thinking you can only do 1 per second to force yourself think about how to work under this conditions.

And like mentioned, this is only relevant when you update the database, gets and queries should scale as needed.

答案3

得分: 1

我不认为你在这里漏掉了什么。以前,当我写入同一实体组时,我也遇到了相同的限制,但最近(事实上是本周)我没有遇到延迟。我愿意提出谷歌已经解决了这个问题,并希望有人能证明我是正确的。

英文:

I don't think you're missing anything here. Previously, I had seen the same limitations when writing to the same entity group but recently (this week, in fact) I have not seen the delays. I'm willing to suggest that Google has solved this problem, and I'm hoping that someone will prove me correct.

huangapple
  • 本文由 发表于 2015年2月28日 05:53:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/28774980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定