Firestore文档“争用太多":实时数据库中是否有此类内容? [英] Firestore Document "Too much contention": such thing in realtime database?

查看:55
本文介绍了Firestore文档“争用太多":实时数据库中是否有此类内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个应用程序,可以让人们出售活动门票.每当售票时,我都会在Firestore中更新代表事件票证的文档以更新统计信息.

I've built an app that let people sell tickets for events. Whenever a ticket is sold, I update the document that represents the ticket of the event in firestore to update the stats.

在高峰时间,此文档会进行很多更新(也许每秒更新10次).有时,由于存在争用过多"这一事实,导致对该项目文档的交易失败,这是由于删除了统计信息更新而导致统计信息不准确.我想这是文档负担很大的结果.

On peak times, this document is updated quite a lot (10x a second maybe). Sometimes transactions to this item document fail due to the fact that there is "too much contention", which results in inaccurate stats since the stat update is dropped. I guess this is the result of the high load on the document.

为解决此问题,我正在考虑将项目的统计信息从Firestore中的项目文档移至实时数据库.在执行此操作之前,我想确保这将真正解决我对项目文档进行争用时遇到的问题.实时数据库能否比Firestore文档更好地处理此类负载?将此类数据移至实时数据库是否被认为是一种好习惯?

To resolve this problem, I am considering to move the stats of the items from the item document in firestore to the realtime database. Before I do, I want to be sure that this will actually resolve the problem I had with the contention on my item document. Can the realtime database handle such load better than a firestore document? Is it considered good practice to move such data to the realtime database?

推荐答案

您遇到的问题是

The issue you're running into is a documented limit of Firestore. There is a limit to the rate of sustained writes to a single document of 1 per second. You might be able to burst writes faster than that for a while, but eventually the writes will fail, as you're seeing.

实时数据库具有不同的记录的限制.它以写入 entire 数据库的总数据量来衡量.该限制为每分钟64MB .如果您想移至Realtime Database,只要您处于该限制之下,就可以了.

Realtime Database has different documented limits. It's measured in the total volume of data written to the entire database. That limit is 64MB per minute. If you want to move to Realtime Database, as long as you are under that limit, you should be OK.

如果您正在Firestore中有效地实现计数器或其他一些数据聚合,则还应该查看

If you are effectively implementing a counter or some other data aggregation in Firestore, you should also look into the distributed counter solution that works around the per-document write limit by sharding data across multiple documents. Your client code would then have to use all of these document shards in order to present data.

至于这些方法中的任何一项是否是良好实践",这是一个见解,这对于Stack Overflow来说是不合时宜的.为您的用例做任何可行的事情.我听说有人成功使用了其中一种.

As for whether or not any one of these is a "good practice", that's a matter of opinion, which is off topic for Stack Overflow. Do whatever works for your use case. I've heard of people successfully using either one.

这篇关于Firestore文档“争用太多":实时数据库中是否有此类内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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