数据存储:对事务内的实体组进行多次写入超出写入限制? [英] Datastore: Multiple writes against an entity group inside a transaction exceeds write limit?
问题描述
我熟悉Datastore对实体组的单写每秒限制(可能为5)。如何与交易平方?
文档似乎表明我可以在一个交易中进行多重修改 - 例如添加几个后代实体:
单个事务可以修改单个组中的多个实体
,或者通过将新实体的父项设置为
来为组添加新实体
https://cloud.google.com/appengine/docs/java/datastore/transactions
是的,您可以在同一个事务中为每个实体组执行多个写操作,但要小心:
在最终的一致性和写作方法之间取得平衡并不是微不足道的。这个可能是有趣的:将所有数据存储实体放入单个组中的目的是什么?
将信用更新为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屋!