firebase - Firebase 中的连接是如何计算的

标签 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

  • 代码
    为简单起见,我只是将所有内容都放在生成代码的主 Controller 中。
    为了测试使用 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("users");
    $scope.fb_child_mike = $scope.fb_child_users.$child("mike");
    
    然后我将这些对象绑定(bind)在我的 View 中,以便我可以看到它们,并且我通过我的 firebase forge 更新数据并在我的应用程序上实时观察数据更新。
    结果
    我将我的本地应用程序打开到 17 个浏览器选项卡中,希望大量选项卡会夸大连接方法之间的任何差异。
    我发现每个选项卡只为每个 firebase 数据库打开一个返回到 firebase 的 web 套接字连接。因此,在测试结束时,两种方法都产生了相同的 17 个连接峰值。
    结论
    通过这个简单的测试,我认为可以肯定地说 Firebase JS 库在管理其连接方面做得很好。
    无论您的代码多次调用 new Firebase() 还是通过 .child() 引用子位置,就您的计量而言,该库都只会创建一个连接。只要您的应用程序处于打开状态,该连接就会保持在线状态。
    所以在你的例子中 - 是的,我相信你会看到 6 个并发连接,1 个用于有人发送消息的应用程序,5 个用于接收消息的应用程序。
    更新
    另一件值得一提的事情是,Firebase 根据当月使用率的 95% 来衡量付费计划的连接。这列在其定价页面 @ https://www.firebase.com/pricing.html 的常见问题部分中
    2016 年 3 月 11 日更新:Firebase 似乎不再基于 95% 来衡量连接。相反,第 101 个并发连接被拒绝。
    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 - Firebase 中的连接是如何计算的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19466522/

    相关文章:

    firebase - Firebase 存储定价是按月收费的吗?

    javascript - 按日期范围的 Firebase 查询

    ios - 使用 Firebase Storage 的 putFile() 方法导致 : The file “fileName” couldn’t be opened error

    javascript - Firebase Push() 方法随机播放列表数据

    ios - Firebase 插入具有 2 个关键属性的数据

    android - 为什么我在 android 7 上收到多个 FCM 通知

    javascript - 使用 ngrx 效果捕获 Firebase Auth 错误

    ios - Firebase 和 Stripe : Storing users credit card information

    swift - 使用存储在 Firebase 数据库中的数据填充 UITableView

    swift - 带查询的 Firebase 实时数据库定价