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

后端 未结 1 1615
生来不讨喜
生来不讨喜 2020-12-12 03:54

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 tha

相关标签:
1条回答
  • 2020-12-12 04:12

    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

    0 讨论(0)
提交回复
热议问题