Reputation: 597
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...
Upvotes: 0
Views: 1467
Reputation: 138869
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.
Upvotes: 2