john lee
john lee

Reputation: 740

firebase realtimeDB simultaneous connected?

My app run in background. If app run in background, is still simultaneous connected with realtimeDB? Or if this app doesn't use realtimeDB for a while, does not count simultaneous connected?

If it's count anyway, can I only get 100,000 user?

Upvotes: 3

Views: 1033

Answers (2)

Gowrav
Gowrav

Reputation: 189

I am answering your three part question in order..,

  1. Firebase database library manages the connection to your database in the backend and this starts right away at the start of the app and this starts counting against your simultaneous connections and when this limit reaches the Max Connections limit of 100k any new connections will be dropped until the existing connections drop by either closing the app or app goes offline after a specified time-out or forcefully closing the DB connections by calling

    FirebaseDatabase.getInstance().goOffline()

    You can however know the whether a given client is connected or not by using the listener at FirebaseDatabase.getInstance().getReference(".info/connected") this however works locally and doesn't explicitly connect to FirebaseDatabase cloud instance., more can be read here

  2. Once you implement the above connection listener you will see that the SDK manages this dynamically in a way that the connections disconnect automatically if there are no listeners attached and if no DB operations like .setValue() are made in the app in last 60 seconds.., but the presence of ValueEventListners will override this and will ensure continuous connectivity with the DB. again this can be overridden and the connection can be severed by explicitly calling FirebaseDatabase.getInstance().goOffline()

  3. Coming to the Max Limit of 100k simultaneous users; as can be seen in Firebase Plans

    There is a limit of 100,000 simultaneous connections per database on the Flame and Blaze plans. See Pricing FAQ for more information.

    If you cross this and for scaling you need to increase the limit, you can explicitly ask Google Firebase Team for the support and they will handle this on a case by case basis to ensure your app can scale as required when required..

    What is a "simultaneous database connection"?

    A simultaneous connection is equivalent to one mobile device, browser tab, or server app connected to the database. Firebase imposes hard limits on the number of simultaneous connections to your app's database. These limits are in place to protect both Firebase and our users from abuse.

    The Spark plan limit is 100 and cannot be raised. The Flame and Blaze plans have a limit of 100,000 simultaneous connections per database. If you need more than 100,000 simultaneous connections, contact Firebase support.

    This limit isn't the same as the total number of users of your app, because your users don't all connect at once. We encourage you to monitor your peak simultaneous database connections and upgrade or add more databases if needed.

Upvotes: 3

Alex Mamo
Alex Mamo

Reputation: 138834

Your app is connected to the realtimeDB as long as your listener is active. If you want to stop listening you need to remove the listener according to your needs and to the activity cycle.

For Android you can use this code in your onDestroy() method.

databaseReference.removeEventListener(valueEventListener);

Hope it helps.

Upvotes: 3

Related Questions