Datastore: Multiple writes against an entity group inside a transaction exceeds write limit?

馋奶兔 提交于 2019-12-29 01:57:08

问题


I'm familiar with Datastore's single-write-per-second limit (ok, 5, maybe) for entity groups. How does that square with transactions?

The docs seem to indicate that I can do multiple modifications inside a transaction- for example adding several descendant entities:

A single transaction can modify multiple entities in a single group, or add new entities to the group by making the new entity's parent an existing entity in the group.

https://cloud.google.com/appengine/docs/java/datastore/transactions


回答1:


Yes, you can do multiple write operations per entity group inside the same transaction, but with care:

  • pay atention to not have writes causing conflicts inside the same transaction, otherwise the transaction will eventually fail (even after retries)
  • try to keep the amount of writes inside each transaction low or somehow ensure ample intervals between transactions such that the aggregate write ops rate (or rather its short-term average) remains (well) below the 1 write/s limit - to leave room for momentary peaks and occasional retries on failures which chew on that limit as well. Otherwise you'll get concurrency/contention exceptions. See Objectify - many writes to same entity in short period of time with and without transaction

And, of course, you can write to up to 25 entity groups (at this time) inside cross-group transactions (each getting its own ~1 write/s limit, for an aggregate of up to ~25 writes/s).

Striking the right balance between eventual consistency and write throuput is not trivial. This might be of interest: What would be the purpose of putting all datastore entities in a single group?

Update credit to DanMcGrath's comment:

It's technically 1 write transaction per second per Entity Group, where a transaction can have up to 500 entities for a single Entity Group. This means you can, at maximum, write 500 entities per second into a single Entity Group. Also note, you can peak higher at once per second, although if you sustain it you increase your risk of hitting contention as well as the eventual consistency of the system. – Dan McGrath 1 hour ago



来源:https://stackoverflow.com/questions/38277246/datastore-multiple-writes-against-an-entity-group-inside-a-transaction-exceeds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!