0

I am developing an android application using firebase realtime database. I want 2 solution.

1) Now I cannot get any data for how many users are active (concurrent user).

2) If any option for reduce the connection limit. like now I have 100 connections if any option to reduce the connection limit into 5 because why I am asking I want to check what will happen in after 100th connection.

I spent more time but no result.

I hope you someone to give me a solution.

thanks...

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mathan Chinna
  • 587
  • 6
  • 22

1 Answers1

2

If you want to know how many users are connected, you need to detect the connection state. Firebase Realtime Database provides a special location at:

/.info/connected

Which is updated every time the Firebase Realtime Database client's connection state changes. Here is an example from the offical documentation.

DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
        boolean connected = snapshot.getValue(Boolean.class);
        if (connected) {
            System.out.println("connected");
        } else {
            System.out.println("not connected");
        }
    }

    @Override
    public void onCancelled(DatabaseError error) {
        System.err.println("Listener was cancelled");
    }
});

/.info/connected is a boolean value which is not synchronized between Realtime Database clients because the value is dependent on the state of the client. In other words, if one client reads /.info/connected as false, this is no guarantee that a separate client will also read false.

This is also a post that i recomand you read for a better understanding.

Regarding the second question, if you'll reach the maximum number of writes per second, it doesn't mean that you'll not be able to use Firebase database anymore. When 1001th simultaneous connection occurs, a queue of operations is created and Firebase will wait until one connection is closed, and than it uses your new connection.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • thank you @alexmamo . if any option to change the connection limit . – Mathan Chinna Dec 13 '17 at 11:09
  • 1
    You can change the connection limit by changing the plan. See the [pricing list](https://firebase.google.com/pricing/). Do you think my answer helped you? – Alex Mamo Dec 13 '17 at 11:15
  • Ok . And one more questions is ,when 100 connection is closed if automatically change second database or pro-grammatically we can change it – Mathan Chinna Dec 13 '17 at 11:24
  • There is no need to use another database, if this is what you were asking for. 100 simultaneous connections is enough for starting. Later if your app grows, you need to consider to change the plan. – Alex Mamo Dec 13 '17 at 11:56
  • is on processing .. once i need your help i will ask u .. thanks you so much – Mathan Chinna Dec 16 '17 at 04:30
  • I using load more query from this ref query (https://stackoverflow.com/a/42502518/6477998) bt it show `java.lang.IllegalArgumentException: You must use startAt(String value), endAt(String value) or equalTo(String value) in combination with orderByKey(). Other type of values or using the version with 2 parameters is not supported` how to solve it. – Mathan Chinna Dec 18 '17 at 06:40