Managing Firebase simultaneous connections to connect to a database instance for only as long as required

172 views
Skip to first unread message

Latif.H

unread,
May 9, 2018, 1:16:48 PM5/9/18
to Firebase Google Group
 When adding multiple databases to a project, I want to know the best approach to enabling/opening and closing connections.


  • Does using the .goOffline() and .goOnline() methods on a database instance establish a new connection each time or temporarily close/free and open connections? My concern is adding overhead costs (Protocol, SSL, etc).

    1) if you connect to a database instance like so:

    ref = Database.database("https://testapp-1234.firebaseio.com").reference()
    

    2) then call a .goOffline() method on it

    3) then again reference to the database later in the app like done in (1) will it establish a new connection? Is this an example of ...frequent, short connections? My concern coming from this Link

  • Further, is this even the right approach to stay connected to a database for as long as is necessary? Which then begs the question if .goOffline() method is even required to close a connection if there are no active listeners or pending write requests for the IOS SDK?

Firebase documentation for Android says:

On Android, Firebase automatically manages connection state to reduce bandwidth and battery usage. When a client has no active listeners, no pending write or onDisconnect operations, and is not explicitly disconnected by the goOffline method, Firebase closes the connection after 60 seconds of inactivity.

  • Why is this not true for IOS?

Kato Richardson

unread,
May 11, 2018, 8:03:35 AM5/11/18
to Firebase Google Group
Hi Latif,

Firebase uses websocket connections. Calling goOffline() severs that connection. Calling goOnline() reestablishes the connection (is the same as creating a new connection). The number of concurrents is counted by the number of open socket connections. Whether it's "short lived" or not just depends on how often you do this.

As a general rule, you shouldn't need to manage these. Firebase takes care of your connectivity. If your app is very sensitive to the number of connections, and you aren't willing to upgrade to the pay as you go plan (i.e. Blaze)--which includes the same amount of free usage by the way--then managing goOffline/goOnline may be useful. Note that you can avoid the need to manage connections by using GET requests via the REST API, which doesn't establish a connection or count against your concurrents. But keep in mind that this removes the realtime capabilities of Realtime Database, which increases complexity and reduces responsiveness of your apps.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/5c1e1250-0a50-4ddf-a56b-73464284300e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages