Firebase性能:每个节点有多少个孩子? [英] Firebase Performance: How many children per node?
问题描述
如果一个节点有1亿个孩子,如果我有一个性能影响:
a)查询,但限制为10个结果
b)只能看一个孩子
我可以将数据分成多个父母,但在我的情况下,我会有一个参考孩子,所以可以直接查找它(这降低了复杂性)。如果有影响,那么在性能下降之前每个场景的最大数量是多少?解析方案
如果节点有那么多孩子,以任何方式访问节点是一个问题的秘诀。访问一个孩子从来都不是问题。
查询一个子节点的节点仍然要求数据库考虑每个孩子。如果你要求最后的10个项目中的10个,你要求数据库考虑你显然不感兴趣的999,999,990个项目。
这是不可能的说最大的是什么,没有一个更具体的数据大小,排序标准等的具体描述。但说实话,即使那么最好的你可能得到的是一个巨大的差异,可能会随着时间的推移而变化。
您在Firebase(以及大多数NoSQL解决方案)中的最佳做法是以适合您应用程序使用该数据的方式对数据进行建模。例如:如果您需要向用户显示最新的10个项目,请将这些最新的10个项目(的键)存储在单独的列表中。
项目
-K ........ 0
标题:Firebase性能:每个节点有多少个子项?
body:如果一个节点有1亿个孩子,如果我:...
-K ........ 1
title: Firebase 3x方法将不会在真正的设备上工作,但在模拟器swift 3.0
身体:我们正在与谷歌Firebase 3X版本,我们面临着...
。
。
。
-K999999998
-K999999999
最近
-K999999990:true
-K999999991:true
-K999999992:true
-K999999993:true
-K999999994:true
-K999999995:true
-K999999996:true
-K999999997:true
-K999999998:true
-K999999999:true
我不确定在那里是否有正确数目的九个字,但是我希望你明白。
If a node has 100 million children, will there be a performance impact if I:
a) Query, but limit to 10 results
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.
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.
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
I'm not sure if I got the right number of nines in there, but I hope you get the idea.
这篇关于Firebase性能:每个节点有多少个孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!