firebase上的用户数量(未注销)是否等于同时连接的数量? [英] Does the number of users ( not logged out ) on app equal no of simultaneous connections on firebase?

查看:155
本文介绍了firebase上的用户数量(未注销)是否等于同时连接的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序开发,我期望有超过100名用户。该应用程序有一个注销按钮,但我怀疑任何用户将注销,他们会推到背景。
所以我的问题是,如果我有150个用户(登录,但在后台)意味着我有150个同时连接?我读了几个关于同时连接的问题,但有人可以更准确地知道什么是并发连接。
150位用户 - 登录(后台) - 在不同的时间打开应用程序 - ?
如果这将超过firebase的免费计划,我该如何防止它?我使用电子邮件/密码登录。

解决方案

当您启动使用Firebase数据库的应用程序时,它会创建与Firebase服务器的持续连接。这可以算作后端的一个活动连接。



连接可以在下列情况下破坏:


  1. 用户没有写入任何数据,并且几分钟内没有任何活动的侦听器(目前只有5分钟,但可以更改)。您打电话给
  2. goOffline()在您的代码中

无论应用程序处于前台还是背景与Firebase SDK无关。但是您可以使用Android生命周期事件(如 onPause())来检测这种转换并删除您的侦听器(以获得条件1)。 b
$ b

另外:当您的应用程序停滞时,Android操作系统可能随时关闭从客户端到Firebase后端的连接。最后一个选项(正如Firebaser的同事Doug在评论中指出的那样)是启用自动资源管理。如果启用自动资源管理,则当应用程序进入后台时,客户端本质上会调用 goOffline(),并且 goOnline()

I have an android app developed and I am expecting more than a 100 users.The app does have a logout button but I doubt any user would logout,they would instead push it to background. So my question is if I have 150 users ( logged in ,but in background) mean that I have 150 simultaneous connections ? I did read a few questions on simultaneous connections , but can someone be more accurate on what is a concurrent connection. 150 users - logged in (background) - open app at different times - ? If this is going to exceed the free plan on firebase , how do i prevent it?.I use email/password for login.

解决方案

When you start an app that uses the Firebase Database, it creates a persistent connection to the Firebase server. This counts as one active connection on the back-end.

The connection can be broken when:

  1. the user hasn't written any data and doesn't have any active listeners for a few minutes (currently 5 minutes, but that could change).
  2. you call goOffline() in your code

Whether the app is in the foreground or background is irrelevant to the Firebase SDK. But you could use Android life-cycle events (such as onPause()) to detect such transitions and remove your listeners (to get to condition 1).

Also: when your app is backgrounded, the Android operating system might close the connection from the client to the Firebase back-end at any time. When it does this depends on the version and flavor of Android your device has.

A final option (as fellow Firebaser Doug pointed out in the comments) is to enable automatic resource management. If you enable automatic resource management, the client will essentially call goOffline() when the app goes into the background and goOnline() when it comes back to the foreground.

这篇关于firebase上的用户数量(未注销)是否等于同时连接的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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