Firebase 中的连接是如何计算的 [英] How the Connection is calculated in Firebase

查看:22
本文介绍了Firebase 中的连接是如何计算的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算连接?

假设我有一个 Web 应用程序,其中一个负载向所有连接的客户端发送消息,假设我有 5 个连接的客户端.这是否意味着只要带有 Web 应用程序的浏览器选项卡处于打开状态,它就会计为 1 个连接,这意味着我将有 6 个并发连接,这也计入您在定价页面中定义的连接"?

如果不是,请解释您如何计算连接".谢谢

解决方案

这个问题一直困扰着我,因为我浏览了 thinkster.io angular+firebase 教程,我看到我的 firebase 分析选项卡显示峰值并发为 6,即使我只记得打开了一页.我回顾了代码,认为这可能与教程如何为您的 Firebase 中的每个位置创建一个新的 Firebase(url) 相关.

我想测试创建新 Firebase(url) 与获取根引用然后访问 .child() 位置之间的区别.我的理论是 new Firebase(url) 每次都会创建一个新连接,而 .child() 会重新使用现有连接.

设置

  • 创建了两个具有相同数据的新 Firebase
  • 使用 yeoman 设置 angularjs 项目
  • 包含 angularfire

代码

为简单起见,我只是将所有内容都放在生成代码的主控制器中.

为了测试使用 new Firebase() 创建的连接,我执行了以下操作:

$scope.fb_root = $firebase(new Firebase(FBURL_NEW));$scope.fb_root_apps = $firebase(new Firebase(FBURL_NEW + '/apps'));$scope.fb_root_someApp = $firebase(new Firebase(FBURL_NEW + '/apps/someApp'));$scope.fb_root_users = $firebase(new Firebase(FBURL_NEW + '/users'));$scope.fb_root_mike = $firebase(new Firebase(FBURL_NEW + '/users/mike'));

为了测试使用 ref.$child() 创建的连接,我执行了以下操作:

$scope.fb_child = $firebase(new Firebase(FBURL_CHILD));$scope.fb_child_apps = $scope.fb_child.$child(apps");$scope.fb_child_someApp = $scope.fb_child_apps.$child(someApp");$scope.fb_child_users = $scope.fb_child.$child(用户");$scope.fb_child_mike = $scope.fb_child_users.$child(mike");

然后我将这些对象绑定在我的视图中以便我可以看到它们,并且我通过我的 firebase forge 更新数据并在我的应用程序上实时观察数据更新.

结果

我将本地应用打开到 17 个浏览器选项卡中,希望大量选项卡会夸大连接方法之间的任何差异.

我发现每个选项卡只为每个 firebase 数据库打开一个返回到 firebase 的 Web 套接字连接.因此,在测试结束时,两种方法都产生了相同的 17 个连接峰值.

结论

从这个简单的测试来看,我认为可以肯定地说 Firebase JS 库在管理其连接方面做得很好.

无论您的代码多次调用 new Firebase() 还是通过 .child() 引用子位置,库都只会创建一个连接就您的计量而言.只要您的应用处于打开状态,该连接就会保持在线状态.

所以在您的示例中 - 是的,我相信您会看到 6 个并发连接,1 个用于发送消息的应用程序,5 个用于接收消息的应用程序.

更新

另一件值得一提的事情是,Firebase 会根据当月的 95% 的使用情况来衡量付费计划的连接数.这列在他们定价页面的常见问题部分@https://www.firebase.com/pricing.html

16 年 3 月 11 日更新:Firebase 似乎不再根据 95% 来衡量连接.相反,第 101 个并发连接被拒绝.

https://www.firebase.com/pricing.html:

<块引用>

我们所有的计划都对数据库连接数有硬性限制.我们的 Free 和 Spark 计划仅限于 100.提高.所有其他计划的礼貌限制为 10,000 个数据库连接.这可以删除以永久允许无限如果您通过 firebase-support@google.com 向我们发送电子邮件,则可以联系我们.我们施加此礼节限制的原因是为了防止滥用并确保我们准备好处理我们最大的客户.请联系至少提前 24 小时通知我们,以便我们取消此限制并确保我们有足够的容量来满足您的需求.

How are the connections are being calculated?

Let's assume that I have a web app which one load sends a message to all connected clients, and let's say I have 5 connected clients. Does it means that as long as the browser tab with the web app is open it will count as 1 connections, which means that I will have 6 concurrent connections and that's count towards what you define as "Connection" in the pricing page?

If not, please explain how you calculate the "Connection". Thanks

解决方案

This question was bugging me ever since I ran through the thinkster.io angular+firebase tutorial and I saw my firebase analytics tab showing a peak concurrent of 6 even though I only remember having the one page open. I looked back at the code and thought it could be to do with how the tutorial has you create a new Firebase(url) for each location in your firebase.

I wanted to test the difference between creating a new Firebase(url) vs taking the root reference and then accessing the .child() location. My theory was that new Firebase(url) would create a new connection each time, while .child() would re-use the existing connection.

Setup

  • Created two new firebases each with identical data
  • Setup an angularjs project using yeoman
  • Included angularfire

Code

For simplicity, I just put everything in the main controller of the generated code.

To test out the connections created with new Firebase() I did the following:

$scope.fb_root = $firebase(new Firebase(FBURL_NEW));
$scope.fb_root_apps = $firebase(new Firebase(FBURL_NEW + '/apps'));
$scope.fb_root_someApp = $firebase(new Firebase(FBURL_NEW + '/apps/someApp'));
$scope.fb_root_users = $firebase(new Firebase(FBURL_NEW + '/users'));
$scope.fb_root_mike = $firebase(new Firebase(FBURL_NEW + '/users/mike'));

To test out the connections created with ref.$child() I did the following:

$scope.fb_child = $firebase(new Firebase(FBURL_CHILD));
$scope.fb_child_apps = $scope.fb_child.$child("apps");
$scope.fb_child_someApp = $scope.fb_child_apps.$child("someApp");
$scope.fb_child_users = $scope.fb_child.$child("users");
$scope.fb_child_mike = $scope.fb_child_users.$child("mike");

I then bound these objects in my view so I can see them, and I played around with updating data via my firebase forge and watching the data update live on my app.

Results

I opened up my local app into 17 browser tabs, hoping that a large number of tabs would exaggerate any differences between the connection methods.

What I found is that each tab only opened up one single web socket connection back to firebase for each firebase db. So at the end of the test, both methods resulted in the same peak count of 17 connections.

Conclusion

From this simple test I think it's safe to say that the Firebase JS library does a good job of managing its connection.

Regardless of your code calling new Firebase() a bunch of times, or by referencing child locations via .child(), the library will only create a single connection as far as your metering is concerned. That connection will stay online for as long as your app is open.

So in your example - yes I believe you will see 6 concurrent connections, 1 for the app where someone is sending the message, and 5 for the apps receiving the message.

Update

One other thing worth mentioning is that Firebase measures connections for paid plans based on the 95th percentile of usage during the month. This is listed in the FAQ section of their Pricing page @ https://www.firebase.com/pricing.html

Update 11-Mar-16: Firebase no longer appears to measure connections based on 95th %. Instead, the 101st concurrent connection is denied.

https://www.firebase.com/pricing.html :

All our plans have a hard limit on the number of database connections. Our Free and Spark plans are limited to 100. The limit cannot be raised. All other plans have a courtesy limit of 10,000 database connections. This can be removed to permanently allow Unlimited connections if you email us at firebase-support@google.com.. The reason we impose this courtesy limit is to prevent abuse and to ensure that we are prepared to handle our largest customers. Please contact us at least 24 hours in advance so we can lift this limit and ensure we have enough capacity available for your needs.

这篇关于Firebase 中的连接是如何计算的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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