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

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

问题描述

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

如果不是,请解释如何计算连接。谢谢

解决方案

这个问题在我运行thinkster.io angular + firebase教程后就开始了,我看到了我的firebase分析显示一个高峰并发的6,即使我只记得有一个页面打开。我回头看了一下代码,并认为这可能与教程如何为您的Firebase中的每个位置创建一个新的Firebase(url)有关。



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


$ b

安装程序




  • 创建两个具有相同数据的新的firebases
  • 使用yeoman设置一个angularjs项目
  • 包含的角色火

    $ b $ h1代码

    为简单起见,我只是把所有东西放在生成的代码的主控制器中。

    为了测试用新的Firebase()创建的连接,我做了以下操作:

      $ scope.fb_root = $ firebase(new Firebase(FBURL_NEW)); 
    $ scope.fb_root_apps = $ firebase(新的Firebase(FBURL_NEW +'/ apps'));
    $ scope.fb_root_someApp = $ firebase(新的Firebase(FBURL_NEW +'/ apps / someApp'));
    $ scope.fb_root_users = $ firebase(新的Firebase(FBURL_NEW +'/ users'));
    $ scope.fb_root_mike = $ firebase(新的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(users);
    $ scope.fb_child_mike = $ scope.fb_child_users。$ child(mike);

    然后我将这些对象绑定在我的视图中,这样我就可以看到它们,

    结果



    我打开了我的本地应用程序到17个浏览器选项卡,希望大量的选项卡会夸大连接方法之间的差异。

    我发现每个选项卡只打开一个单一的网络套接字连接返回到firebase的每个firebase数据库。所以在测试结束时,两种方法的结果都是相同的17个连接的峰值计数。

    结论



    从这个简单的测试中,我认为可以肯定地说,Firebase JS库在管理连接方面做得很好。无论您的代码是多次调用新的Firebase(),还是通过.child()引用子地点,该库都将只创建一个单独的连接因为你的计量是关心的。只要您的应用程序打开,该连接将保持在线状态。



    因此,在您的示例中 - 是的,我相信您会看到6个并发连接,正在发送消息,5为接收消息的应用程序。



    更新



    另外值得一提的是Firebase是根据当月使用量的百分之九十五来衡量付费计划的连接。这在定价页面的常见问题部分列出@ https://www.firebase.com/pricing.html



    更新于2016年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天全站免登陆