数据存储:对事务内的实体组进行多次写入超出写入限制? [英] Datastore: Multiple writes against an entity group inside a transaction exceeds write limit?

查看:74
本文介绍了数据存储:对事务内的实体组进行多次写入超出写入限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉Datastore对实体组的单写每秒限制(可能为5)。如何与交易平方?



文档似乎表明我可以在一个交易中进行多重修改 - 例如添加几个后代实体:


单个事务可以修改单个组中的多个实体
,或者通过将新实体的父项设置为
来为组添加新实体


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

解决方案

是的,您可以在同一个事务中为每个实体组执行多个写操作,但要小心:


  • 请注意不要在同一个事务中写入导致冲突,否则事务最终会失败(甚至在重试后)

  • 尽量保持写入内部的数量每笔交易低或以某种方式确保交易之间有足够的间隔,从而使总写入操作速率(或其短期平均值)保持(良好)低于1写/秒限制 - 为出现故障的临时峰值和偶尔重试留下空间咀嚼也是如此。否则,你会得到并发/争用异常。请参阅物化 - 许多在短时间内写入相同的实体,不论有无交易 到25个实体组(此时)在跨组交易内部(每个组获得约1个写/秒的限制,合计高达约25个写/秒)。

    在最终的一致性和写作方法之间取得平衡并不是微不足道的。这个可能是有趣的:将所有数据存储实体放入单个组中的目的是什么?



    将信用更新为DanMcGrath的评论:

    lockquote
    技术上,每个实体组每秒写入一笔交易,
    交易最多可以有500个实体一个实体
    组。这意味着您最多可以将500个实体每秒
    写入单个实体组。另外请注意,您可以每
    秒一次达到最高点,但如果持续下去,则会增加您遇到
    争用的风险以及系统的最终一致性。 - Dan
    McGrath 1小时前



    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

    解决方案

    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

    这篇关于数据存储:对事务内的实体组进行多次写入超出写入限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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