Firebase 性能:每个节点有多少个子节点? [英] Firebase Performance: How many children per node?

查看:34
本文介绍了Firebase 性能:每个节点有多少个子节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个节点有 1 亿个子节点,如果我:

If a node has 100 million children, will there be a performance impact if I:

a) 查询,但限制为 10 个结果

a) Query, but limit to 10 results

b) 只看其中一个孩子

b) Watch one of the children only

我可以将数据拆分为多个父级,但在我的情况下,我将引用子级,因此可以直接查找(这降低了复杂性).如果有影响,在性能下降之前每个场景的最大数量是多少?

I could split the data up into multiple parents, but in my case I will have a reference to the child so can directly look it up (which reduces the complexity). If there is an impact, what is the maximum number for each scenario before performance is degraded?

推荐答案

如果一个节点有那么多子节点,以任何方式访问该节点都会导致问题.访问单个孩子从来都不是问题.

If a node has that many children, accessing the node in any way is a recipe for problems. Accessing an individual child is never a problem.

查询节点的子节点子集仍然需要数据库考虑这些子节点中的每一个.如果您请求 1 亿个项目中的最后 10 个,您就是在要求数据库考虑您显然不感兴趣的 999,999,990 个项目.

Querying the node for a subset of its children still requires that the database consider each of those children. If you request the last 10 out of 100 million items, you're asking the database to consider 999,999,990 items that you're apparently not interested in.

如果没有对数据大小、排序标准等更具体的描述,就不可能说出最大值是多少.但老实说,即使这样,您可能得到的最好值也是一个具有巨大差异的值这可能会随着时间的推移而改变.

It is impossible to say what the maximum is without a way more concrete description of the data size, ordering criteria, etc. But to be honest, even then the best you're likely to get is a value with a huge variance that is likely to change over time.

您在 Firebase(以及大多数 NoSQL 解决方案)中的最佳方法是以适合您的应用如何使用该数据的方式对数据进行建模.例如:如果您需要向用户显示最新的 10 个项目,请将最近 10 个项目的(键)存储在单独的列表中.

You best approach in Firebase (and most NoSQL solutions) is to model the data in a way that fits with how your app uses that data. So for example: if you need to show the latest 10 items to your users, store the (keys of) those latest 10 items in a separate list.

items
    -K........0
        title: "Firebase Performance: How many children per node?"
        body: "If a node has 100 million children, will there be a performance impact if I:..."
    -K........1
        title: "Firebase 3x method won't working in real device but worked in simulator swift 3.0"
        body: "Hi we are working with google firebase 3x version and we faced..."
    .
    .
    .
    -K999999998
    -K999999999
recent
    -K999999990: true
    -K999999991: true
    -K999999992: true
    -K999999993: true
    -K999999994: true
    -K999999995: true
    -K999999996: true
    -K999999997: true
    -K999999998: true
    -K999999999: true

我不确定我在那里得到的 9 的数量是否正确,但我希望你能明白.

I'm not sure if I got the right number of nines in there, but I hope you get the idea.

这篇关于Firebase 性能:每个节点有多少个子节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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